I have a Jenkins pipeline job called "TestPipeline". I want to trigger a build on 2 different slaves which labeled "tester1' and "tester2". And the pipeline script is quite simple here:
node('tester1') { build 'test_job' } node('tester2') { build 'test_job' }
However when I run the TestPipeline job, the "test_job" won't run on the nodes which I assigned. But run on random node instead.
I'm wondering if I should set "Restrict where this project can be run" on my "test_job". So I set it to "tester" (The "tester" label contains both node "tester1" and "tester2"). But when I run the pipeline job again, the "test_job" runs on "tester2" twice. I should expect the job to run on "tester1" first and then run on "tester2". Why is that? Is it because the "node" step doesn't matter when it comes to which node the build step should be built on?
You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.
Please see the bug here. The solution is as follows.
build job: 'test_job', parameters: [[$class: 'LabelParameterValue', name: 'node', label: 'tester1']] build job: 'test_job', parameters: [[$class: 'LabelParameterValue', name: 'node', label: 'tester2']]
And the job will be built as I wanted.
However, I think it is only a workaround. I still believe this is a bug. Because the node step should do its job instead of letting other plugins to do for it.
I did the same, but using Node parameter, so I can use nodes list running job directly, or running pipeline (in pipeline I use Choice parameter to have list of available nodes). So in my case:
node_name
node
, put there possible choices, so running pipeline you can choose on which node it should be run.Code to insert into pipeline script:
build job: 'my_job', parameters: [[$class: 'NodeParameterValue', name: 'node_name', labels: ["$node"], nodeEligibility: [$class: 'AllNodeEligibility']]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With