How to use environment variable in Jenkins Pipeline build?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use environment variable in Jenkins Pipeline build?

ZillaYT
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/829ef574-de14-4277-b391-185d56e485aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

ZillaYT
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/def5cee1-0c4c-4c01-880d-e70531623d33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

Cuong Tran
Where do you define your "environment variable"?   

It should work as ${BRANCH_TO_BUILD} if you define BRANCH_TO_BUILD under global environment variables, folder, inside your pipeline, etc.


On Thursday, November 8, 2018 at 8:56:38 AM UTC-8, ZillaYT wrote:
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7276a5ec-2a73-4665-90e7-90b96298911c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

ZillaYT
It should work, but doesn't!

I define my environment variable in Manage Jenkins->System Configuration, Global Properties, Environment variables. I use the variable in other jobs so I know the variable definition works!

Thanks.

On Thursday, November 8, 2018 at 12:45:18 PM UTC-5, Cuong Tran wrote:
Where do you define your "environment variable"?   

It should work as ${BRANCH_TO_BUILD} if you define BRANCH_TO_BUILD under global environment variables, folder, inside your pipeline, etc.


On Thursday, November 8, 2018 at 8:56:38 AM UTC-8, ZillaYT wrote:
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1bea1dd6-9c66-4117-81b5-31bd55b8134d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

ZillaYT
Just to be clear, this is the text box in the job configuration page where I want to use an environment variable.

Screen Shot 2018-11-08 at 1.37.35 PM.png



On Thursday, November 8, 2018 at 2:19:06 PM UTC-5, ZillaYT wrote:
It should work, but doesn't!

I define my environment variable in Manage Jenkins->System Configuration, Global Properties, Environment variables. I use the variable in other jobs so I know the variable definition works!

Thanks.

On Thursday, November 8, 2018 at 12:45:18 PM UTC-5, Cuong Tran wrote:
Where do you define your "environment variable"?   

It should work as ${BRANCH_TO_BUILD} if you define BRANCH_TO_BUILD under global environment variables, folder, inside your pipeline, etc.


On Thursday, November 8, 2018 at 8:56:38 AM UTC-8, ZillaYT wrote:
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

Mark Waite-2
That's a good clarification.  I believe there is a known bug that the git plugin does not expand variable references in some of the configuration fields.  

Use a multibranch Pipeline instead, then you can let the Pipeline script expand the variable, and you won't have a confusing mix of changes in the history of the job.

Mark Waite

On Thu, Nov 8, 2018 at 12:23 PM ZillaYT <[hidden email]> wrote:
Just to be clear, this is the text box in the job configuration page where I want to use an environment variable.

Screen Shot 2018-11-08 at 1.37.35 PM.png



On Thursday, November 8, 2018 at 2:19:06 PM UTC-5, ZillaYT wrote:
It should work, but doesn't!

I define my environment variable in Manage Jenkins->System Configuration, Global Properties, Environment variables. I use the variable in other jobs so I know the variable definition works!

Thanks.

On Thursday, November 8, 2018 at 12:45:18 PM UTC-5, Cuong Tran wrote:
Where do you define your "environment variable"?   

It should work as ${BRANCH_TO_BUILD} if you define BRANCH_TO_BUILD under global environment variables, folder, inside your pipeline, etc.


On Thursday, November 8, 2018 at 8:56:38 AM UTC-8, ZillaYT wrote:
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtE4SktreTW-4QOhqhnBnHgtrAZV82PtDqw_kFPeM5xiNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to use environment variable in Jenkins Pipeline build?

ZillaYT
I got it answered in stackoverflow How to use environment variables in a Jenkins pipeline job? I just had to uncheck the "Lightweight checkout" box at the bottom of that block, and it worked!

Thanks!

On Thursday, November 8, 2018 at 2:53:03 PM UTC-5, Mark Waite wrote:
That's a good clarification.  I believe there is a known bug that the git plugin does not expand variable references in some of the configuration fields.  

Use a multibranch Pipeline instead, then you can let the Pipeline script expand the variable, and you won't have a confusing mix of changes in the history of the job.

Mark Waite

On Thu, Nov 8, 2018 at 12:23 PM ZillaYT <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="iVdXkDjHAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">zil...@...> wrote:
Just to be clear, this is the text box in the job configuration page where I want to use an environment variable.

Screen Shot 2018-11-08 at 1.37.35 PM.png



On Thursday, November 8, 2018 at 2:19:06 PM UTC-5, ZillaYT wrote:
It should work, but doesn't!

I define my environment variable in Manage Jenkins->System Configuration, Global Properties, Environment variables. I use the variable in other jobs so I know the variable definition works!

Thanks.

On Thursday, November 8, 2018 at 12:45:18 PM UTC-5, Cuong Tran wrote:
Where do you define your "environment variable"?   

It should work as ${BRANCH_TO_BUILD} if you define BRANCH_TO_BUILD under global environment variables, folder, inside your pipeline, etc.


On Thursday, November 8, 2018 at 8:56:38 AM UTC-8, ZillaYT wrote:
Someone suggested using ${env.branchToBuild}, so I tried env.branchToBuild, $env.branchToBuild, ${env.branchToBuild}, and "${env.branchToBuild}" all to NO avail.

On Thursday, November 8, 2018 at 10:26:34 AM UTC-5, ZillaYT wrote:
I have a Jenkins Pipeline job which uses "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 extrapolate the string. I do have that variable defined and use it in other jobs.

Is it just not possible to do this?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="iVdXkDjHAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/264ef2d4-3b6e-471c-8d98-40bc1e16496b%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7d86558f-42a6-4ff7-956b-149d9b719e34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.