How to set environment variable in multibranch pipeline?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set environment variable in multibranch pipeline?

Mark Allison
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/2a847c8e-78ac-44e0-837e-2679435449ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Kevin Burnett
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/35f81b50-ac62-4f9c-8937-b8c600434a8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Mark Allison
Thanks for the reply, but I need to set the variable outside the pipeline script similar to the Environment Injector plugin. Is there a way to do that?

On Tuesday, 13 June 2017 13:36:07 UTC+1, Kevin Burnett wrote:
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/67fe426e-5c0d-4019-8972-d9ac24167fce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Cuong Tran
Why?

On Wednesday, June 14, 2017 at 5:33:26 AM UTC-7, Mark Allison wrote:
Thanks for the reply, but I need to set the variable outside the pipeline script similar to the Environment Injector plugin. Is there a way to do that?

On Tuesday, 13 June 2017 13:36:07 UTC+1, Kevin Burnett wrote:
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/3f7e72cf-a497-4976-a7f4-03cf80dbc635%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Dan Tran
In reply to this post by Mark Allison
Please vote for this  https://issues.jenkins-ci.org/browse/JENKINS-42906


--
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/36cd9f53-c899-4faa-aa7c-4616b2b99543%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Dale Lotts
In reply to this post by Cuong Tran
I need this also so any suggestions on how to get it working would be appreciated.

We are automating publishing and need to pass in npm tokens, user name, passwords, etc in order for publishing to be successful.



On Wednesday, June 14, 2017 at 6:15:34 PM UTC-5, Cuong Tran wrote:
Why?

On Wednesday, June 14, 2017 at 5:33:26 AM UTC-7, Mark Allison wrote:
Thanks for the reply, but I need to set the variable outside the pipeline script similar to the Environment Injector plugin. Is there a way to do that?

On Tuesday, 13 June 2017 13:36:07 UTC+1, Kevin Burnett wrote:
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/91218c1a-612c-452d-8c3d-a396a7d6b3a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

Aseem Patni
The method mentioned by Kevin Burnett should be the right way to do this.

On Monday, June 19, 2017 at 1:30:12 PM UTC-7, Dale Lotts wrote:
I need this also so any suggestions on how to get it working would be appreciated.

We are automating publishing and need to pass in npm tokens, user name, passwords, etc in order for publishing to be successful.



On Wednesday, June 14, 2017 at 6:15:34 PM UTC-5, Cuong Tran wrote:
Why?

On Wednesday, June 14, 2017 at 5:33:26 AM UTC-7, Mark Allison wrote:
Thanks for the reply, but I need to set the variable outside the pipeline script similar to the Environment Injector plugin. Is there a way to do that?

On Tuesday, 13 June 2017 13:36:07 UTC+1, Kevin Burnett wrote:
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/401caba0-8a7e-4edd-b24d-a39168af76ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set environment variable in multibranch pipeline?

stephenconnolly
In reply to this post by Dale Lotts
On Mon, 19 Jun 2017 at 21:30, Dale Lotts <[hidden email]> wrote:
I need this also so any suggestions on how to get it working would be appreciated.

We are automating publishing and need to pass in npm tokens, user name, passwords, etc in order for publishing to be successful.

that sounds like credentials...
 



On Wednesday, June 14, 2017 at 6:15:34 PM UTC-5, Cuong Tran wrote:
Why?

On Wednesday, June 14, 2017 at 5:33:26 AM UTC-7, Mark Allison wrote:
Thanks for the reply, but I need to set the variable outside the pipeline script similar to the Environment Injector plugin. Is there a way to do that?

On Tuesday, 13 June 2017 13:36:07 UTC+1, Kevin Burnett wrote:
here's an example Jenkinsfile that sets an environment variable (REPO_URL) that applies to all stages. you can also use the withEnv step to set an environment variable for a certain block.

pipeline {
  agent
{ label 'docker' }
  environment
{
    REPO_URL
= 'www.my.repo'
 
}
  stages
{
    stage
('build') {
      steps
{
        sh
'env | grep REPO_URL'
     
}
   
}
 
}
}

Jenkinsfiles apply to all branches in a repo, so that part is handled implicitly.

Hope this helps,
KB


On Tuesday, June 13, 2017 at 3:53:33 AM UTC-4, Mark Allison wrote:
I have a Jenkins multibranch pipeline project and I want to set an environment variable for all branches. Is this possible? I could only see a way to do it with the environment injector plugin at the branch level. I want to be able to do this at the project level because I want new feature branches to automatically inherit some environment variables.

--
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/91218c1a-612c-452d-8c3d-a396a7d6b3a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CA%2BnPnMzgr0q9zujyzkvmYXi9r5cWty7NhQxnHvuBRGQUVhW-qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.