How to use environment variables in a Jenkins pipeline job?
up vote
0
down vote
favorite
I posted this in the Jenkins users Google group, but thought I'd post it here too.
I have a Jenkins Pipeline job, and in its Configuration page, I use a "Pipeline script from SCM" as my pipeline. One of this block's parameters is "Branch to build" of course. How can I used an environment variable for the text block? I tried, for example, $branchToBuild, ${branchToBuild} or "${branchToBuild}" and it just takes those as literal values and does not interpolate the string. I do have that variable defined and use it in other jobs.
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail, that is, they are also just taken as literal strings and not interpolated.

Is it just not possible to do this?
jenkins-pipeline
add a comment |
up vote
0
down vote
favorite
I posted this in the Jenkins users Google group, but thought I'd post it here too.
I have a Jenkins Pipeline job, and in its Configuration page, I use a "Pipeline script from SCM" as my pipeline. One of this block's parameters is "Branch to build" of course. How can I used an environment variable for the text block? I tried, for example, $branchToBuild, ${branchToBuild} or "${branchToBuild}" and it just takes those as literal values and does not interpolate the string. I do have that variable defined and use it in other jobs.
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail, that is, they are also just taken as literal strings and not interpolated.

Is it just not possible to do this?
jenkins-pipeline
1
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
1
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I posted this in the Jenkins users Google group, but thought I'd post it here too.
I have a Jenkins Pipeline job, and in its Configuration page, I use a "Pipeline script from SCM" as my pipeline. One of this block's parameters is "Branch to build" of course. How can I used an environment variable for the text block? I tried, for example, $branchToBuild, ${branchToBuild} or "${branchToBuild}" and it just takes those as literal values and does not interpolate the string. I do have that variable defined and use it in other jobs.
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail, that is, they are also just taken as literal strings and not interpolated.

Is it just not possible to do this?
jenkins-pipeline
I posted this in the Jenkins users Google group, but thought I'd post it here too.
I have a Jenkins Pipeline job, and in its Configuration page, I use a "Pipeline script from SCM" as my pipeline. One of this block's parameters is "Branch to build" of course. How can I used an environment variable for the text block? I tried, for example, $branchToBuild, ${branchToBuild} or "${branchToBuild}" and it just takes those as literal values and does not interpolate the string. I do have that variable defined and use it in other jobs.
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail, that is, they are also just taken as literal strings and not interpolated.

Is it just not possible to do this?
jenkins-pipeline
jenkins-pipeline
edited Nov 8 at 18:45
asked Nov 8 at 17:16
Chris F
2,00273165
2,00273165
1
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
1
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34
add a comment |
1
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
1
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34
1
1
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
1
1
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You have to uncheck Lightweight checkout box in order to use a variable as Branch name to build.
It's a known Jenkins bug, here is more information : How to pass project parameter as branch name to build in Jenkins
Apparently the code path is very different if you are using the
lightweight checkout, and that has not been resolved, apparently.
Another source : https://cleverbuilder.com/notes/jenkins-dynamic-git-branch/
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You have to uncheck Lightweight checkout box in order to use a variable as Branch name to build.
It's a known Jenkins bug, here is more information : How to pass project parameter as branch name to build in Jenkins
Apparently the code path is very different if you are using the
lightweight checkout, and that has not been resolved, apparently.
Another source : https://cleverbuilder.com/notes/jenkins-dynamic-git-branch/
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
add a comment |
up vote
1
down vote
accepted
You have to uncheck Lightweight checkout box in order to use a variable as Branch name to build.
It's a known Jenkins bug, here is more information : How to pass project parameter as branch name to build in Jenkins
Apparently the code path is very different if you are using the
lightweight checkout, and that has not been resolved, apparently.
Another source : https://cleverbuilder.com/notes/jenkins-dynamic-git-branch/
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You have to uncheck Lightweight checkout box in order to use a variable as Branch name to build.
It's a known Jenkins bug, here is more information : How to pass project parameter as branch name to build in Jenkins
Apparently the code path is very different if you are using the
lightweight checkout, and that has not been resolved, apparently.
Another source : https://cleverbuilder.com/notes/jenkins-dynamic-git-branch/
You have to uncheck Lightweight checkout box in order to use a variable as Branch name to build.
It's a known Jenkins bug, here is more information : How to pass project parameter as branch name to build in Jenkins
Apparently the code path is very different if you are using the
lightweight checkout, and that has not been resolved, apparently.
Another source : https://cleverbuilder.com/notes/jenkins-dynamic-git-branch/
answered Nov 8 at 19:26
André DS
1,0311315
1,0311315
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
add a comment |
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
1
1
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
Ding, ding, ding, ding... Thanks!
– Chris F
Nov 8 at 19:30
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%2f53212940%2fhow-to-use-environment-variables-in-a-jenkins-pipeline-job%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
Please put your code in your question.
– Matt Schuchard
Nov 8 at 17:26
1
There is NO code, it's just a text box in the Jenkins job configuration page. I edited the post to clarify this.
– Chris F
Nov 8 at 18:34