Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get agent/node name in jenkinsfile?

In jenkinsfile, I have a parallel logic that runs on several nodes, how can I get the agent's name on which the code is being executed on?

like image 508
zanyman Avatar asked Jul 10 '18 14:07

zanyman


People also ask

What is Agent node label in Jenkins?

These new parameter types are 'Node' and 'Label'. This is specially useful if you want to execute the job on different nodes without changing the configuration. It also allows you to use Jenkins in a scenario where you would like to setup different nodes with the same script/jobs configured - e.g. SW provisioning.

How do I check my Jenkins agent status?

Visit a url like http:``//myslave:3141 to see whether a slave is running and how much memory it is using. Configure the port used by clicking Manage Jenkins on the dashboard.

What is agent in Jenkins file?

An agent is typically a machine, or container, which connects to a Jenkins controller and executes tasks when directed by the controller. Artifact. An immutable file generated during a Build or Pipeline run which is archived onto the Jenkins Controller for later retrieval by users.


1 Answers

You can use the NODE_NAME environment variable to fetch the Agent name within the Jenkinsfile. Here is a simple example:

node('master') {
    stage('GetNodeName') {
    def node_name = "${NODE_NAME}"
    echo "The Node Name is: ${node_name}"
    }
}

enter image description here

Here is the link to all the Environment Variables

like image 133
Ravindranath Barathy Avatar answered Oct 19 '22 12:10

Ravindranath Barathy