How to use environment variables in a Jenkins pipeline job?











up vote
0
down vote

favorite
1












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.



Jenkins pipeline configuration



Is it just not possible to do this?










share|improve this question




















  • 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

















up vote
0
down vote

favorite
1












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.



Jenkins pipeline configuration



Is it just not possible to do this?










share|improve this question




















  • 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















up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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.



Jenkins pipeline configuration



Is it just not possible to do this?










share|improve this question















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.



Jenkins pipeline configuration



Is it just not possible to do this?







jenkins-pipeline






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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














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/






share|improve this answer

















  • 1




    Ding, ding, ding, ding... Thanks!
    – Chris F
    Nov 8 at 19:30











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',
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
});


}
});














draft saved

draft discarded


















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

























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/






share|improve this answer

















  • 1




    Ding, ding, ding, ding... Thanks!
    – Chris F
    Nov 8 at 19:30















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/






share|improve this answer

















  • 1




    Ding, ding, ding, ding... Thanks!
    – Chris F
    Nov 8 at 19:30













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/






share|improve this answer












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/







share|improve this answer












share|improve this answer



share|improve this answer










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














  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings