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?
jenkins jenkins-pipeline
add a comment |
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?
jenkins jenkins-pipeline
1
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57
add a comment |
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?
jenkins jenkins-pipeline
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?
jenkins jenkins-pipeline
jenkins jenkins-pipeline
asked Jul 7 '16 at 8:37
Andy Wang
4121310
4121310
1
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57
add a comment |
1
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57
1
1
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57
add a comment |
4 Answers
4
active
oldest
votes
Please see the bug here. The solution is as follows.
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- 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.
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
add a comment |
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:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Node parameter and set the parameter name to
node_name
- In pipeline add Choice parameter, name it
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']]]
add a comment |
I just tested this on my installation, and it correctly ran each script on each node.
You might want to check that you've configured your slaves correctly. I believe the documentation says they need to have the Launch slave agents via Java Web Start setting, you could verify that.
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
add a comment |
Here is how i got it working
create a 'job' 'test_job' with parameter type 'label' , name 'node', value can be any string. (this is the job to be triggered)
.Set 'Restrict where this project can be run' to the label valuecreate a 'pipeline' with parameter type "Node". From the pipeline section, use the following script
Note the label for test_job is ${env.NODE_NAME} which will be set by the pipeline based on user's choice
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38240943%2fhow-to-trigger-a-jenkins-build-on-specific-node-using-pipeline-plugin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please see the bug here. The solution is as follows.
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- 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.
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
add a comment |
Please see the bug here. The solution is as follows.
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- 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.
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
add a comment |
Please see the bug here. The solution is as follows.
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- 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.
Please see the bug here. The solution is as follows.
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Label parameter and set the parameter name to 'node'
- 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.
edited Aug 24 '16 at 15:56
Wilfred Hughes
16.5k1091129
16.5k1091129
answered Jul 13 '16 at 9:14
Andy Wang
4121310
4121310
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
add a comment |
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
2
2
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
As Jesse Glick said: The label on node selects which node is allocated during its block. Wrapping build inside node makes no sense at all; the node context is ignored, you are just wasting an executor slot. Using LabelParameterValue is the appropriate solution for the requested problem.
– Andy Wang
Sep 20 '16 at 8:53
add a comment |
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:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Node parameter and set the parameter name to
node_name
- In pipeline add Choice parameter, name it
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']]]
add a comment |
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:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Node parameter and set the parameter name to
node_name
- In pipeline add Choice parameter, name it
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']]]
add a comment |
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:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Node parameter and set the parameter name to
node_name
- In pipeline add Choice parameter, name it
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']]]
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:
- Install Node and Label parameter plugin
- In test_job's configuration, select 'This build is parameterized' and add a Node parameter and set the parameter name to
node_name
- In pipeline add Choice parameter, name it
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']]]
answered Feb 27 '17 at 10:53
Grysik
355310
355310
add a comment |
add a comment |
I just tested this on my installation, and it correctly ran each script on each node.
You might want to check that you've configured your slaves correctly. I believe the documentation says they need to have the Launch slave agents via Java Web Start setting, you could verify that.
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
add a comment |
I just tested this on my installation, and it correctly ran each script on each node.
You might want to check that you've configured your slaves correctly. I believe the documentation says they need to have the Launch slave agents via Java Web Start setting, you could verify that.
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
add a comment |
I just tested this on my installation, and it correctly ran each script on each node.
You might want to check that you've configured your slaves correctly. I believe the documentation says they need to have the Launch slave agents via Java Web Start setting, you could verify that.
I just tested this on my installation, and it correctly ran each script on each node.
You might want to check that you've configured your slaves correctly. I believe the documentation says they need to have the Launch slave agents via Java Web Start setting, you could verify that.
answered Jul 7 '16 at 17:57
Alex Haynes
98114
98114
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
add a comment |
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
My slaves are launched via ssh. I guess maybe it will work if I change the settings to Java Web Start. So I did test again using Java Web Start. However, the result is the same. The job still runs on random nodes.
– Andy Wang
Jul 11 '16 at 6:07
add a comment |
Here is how i got it working
create a 'job' 'test_job' with parameter type 'label' , name 'node', value can be any string. (this is the job to be triggered)
.Set 'Restrict where this project can be run' to the label valuecreate a 'pipeline' with parameter type "Node". From the pipeline section, use the following script
Note the label for test_job is ${env.NODE_NAME} which will be set by the pipeline based on user's choice
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
add a comment |
Here is how i got it working
create a 'job' 'test_job' with parameter type 'label' , name 'node', value can be any string. (this is the job to be triggered)
.Set 'Restrict where this project can be run' to the label valuecreate a 'pipeline' with parameter type "Node". From the pipeline section, use the following script
Note the label for test_job is ${env.NODE_NAME} which will be set by the pipeline based on user's choice
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
add a comment |
Here is how i got it working
create a 'job' 'test_job' with parameter type 'label' , name 'node', value can be any string. (this is the job to be triggered)
.Set 'Restrict where this project can be run' to the label valuecreate a 'pipeline' with parameter type "Node". From the pipeline section, use the following script
Note the label for test_job is ${env.NODE_NAME} which will be set by the pipeline based on user's choice
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
Here is how i got it working
create a 'job' 'test_job' with parameter type 'label' , name 'node', value can be any string. (this is the job to be triggered)
.Set 'Restrict where this project can be run' to the label valuecreate a 'pipeline' with parameter type "Node". From the pipeline section, use the following script
Note the label for test_job is ${env.NODE_NAME} which will be set by the pipeline based on user's choice
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
script {
build job: 'test_job', parameters: [
[$class: 'LabelParameterValue', name: 'node', label: "${env.NODE_NAME}" ]
]
}}}}}
edited Nov 10 at 17:40
answered Nov 10 at 17:13
cannie
163
163
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38240943%2fhow-to-trigger-a-jenkins-build-on-specific-node-using-pipeline-plugin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I've tried using NodeLabel Parameter Plugin. But I'm stuck on how to specify the "node parameter" in pipeline script. The "Pipeline Syntax" only output like "build job: 'test_print', parameters: [<object of type org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue>]" whichever node I select.
– Andy Wang
Jul 7 '16 at 8:57