1
votes

I have a Jenkins server and two nodes. I want to execute a basic ip a command on a node when it first connect to the Jenkins server.

The problem is that when Node1 connect itself, the job trigger on Node 1 BUT When Node2 connect to the server, the job trigger AGAIN on Node1...

Can you please help me ? I use the java client for my nodes and a label called "Julien"

https://imgur.com/a/qnIX5Oo

Thanks

2

2 Answers

1
votes

Hi you can use the startup trigger plugin which will trigger the jobs on startup of nodes and master. You can also restrict the nodes with there labels for triggering the job.

Also refer this link for more info.

I don't know how to select node for executing command but you can create another pipeline job and write pipeline script e.g.

pipeline {
    agent {label "${Node parameter name}"}
    stages {
        stage("some stage"){
          steps{
           bat "your command"
         }
      }
    }
}
1
votes

The question is quite old now, but I was facing same issue and wanted to share my settings to solve it.

I use the startup trigger plugin, as explained above, but by default, it was using any available node to do the job. In order to make the new connected node run the job, I had to :

  • Check "This project is parameterized"
  • Add a "Node" parameter with "Name" set to "LAST_STARTED_NODE" (it can be anything else)
  • Check "Build when job nodes start"
  • In "Advanced", set "Node parameter name" to "LAST_STARTED_NODE" (same as above)

With this configuration, job is run on expected new node.