Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

How to trigger a jenkins build on specific node using pipeline plugin?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please see the bug here. The solution is as follows.

  1. Install Node and Label parameter plugin
  2. In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
  3. In pipeline script, use code:
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...