How to pass paramater to process environment variable?

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

How to pass paramater to process environment variable?

Idan Adar
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?

--
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/3bb3b123-046a-4c6b-8a7e-655b76a2b5a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Steven Foster
You should define the parameters in the pipeline also:
https://jenkins.io/doc/book/pipeline/syntax/#parameters

currently there is some disconnect in the project configuration UI for pipeline jobs, many of the options there need to actually be defined in the pipeline.

On Wednesday, September 20, 2017 at 8:29:32 AM UTC+1, Idan Adar wrote:
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?

--
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/f353ca4a-32fa-4a6b-8a35-8fe4582f1cca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Idan Adar
Okay.
How can I then use this in combination with: https://github.com/jansepar/node-jenkins-api#build_with_params

I used parameters as a way to test getting a value "externally".
With this working, the end goal is to trigger the job remotely with a parameter, and the parameter's value then needs to be used as an environment variable...

Can this be done with the Parameters pipeline option you've mentioned?

On Wednesday, September 20, 2017 at 12:21:05 PM UTC+3, Steven Foster wrote:
You should define the parameters in the pipeline also:
<a href="https://jenkins.io/doc/book/pipeline/syntax/#parameters" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fsyntax%2F%23parameters\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFRI2TtZcfM2EMQe4-hTWWqaNYT2w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fsyntax%2F%23parameters\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFRI2TtZcfM2EMQe4-hTWWqaNYT2w&#39;;return true;">https://jenkins.io/doc/book/pipeline/syntax/#parameters

currently there is some disconnect in the project configuration UI for pipeline jobs, many of the options there need to actually be defined in the pipeline.

On Wednesday, September 20, 2017 at 8:29:32 AM UTC+1, Idan Adar wrote:
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?

--
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/5227f101-4edb-4add-8c67-3d7f556bdf77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Robert Hales
In reply to this post by Idan Adar
The Parameters can be defined in the pipeline, or in the job configuration, but if you define it in the pipeline, it will update the job configuration the first time it runs. So when you add the parameters to the pipeline, and have none configured in your job, your Build Now button will still be Build Now. Run it once, things may fail and die. But now your job will be configured with the parameters, and the Build Now link now says Build with Parameters. I think it is cleaner to add any config possible in the pipeline code. Also, if you change any property from the pipeline code, it will change all properties in the job config, so if it wasn't specified in the pipeline code, it will disable. So, for example, if you configure the build discarder in the project, then configure parameters in the pipeline code, you will lose your build discarder when the job runs. 

To access the parameters in your pipeline, use the params object: 

parameters {
   
string(defaultValue: 'master', description: 'Git Branch', name: 'gitBranch')
}


...


myProperty
= "${params.gitBranch}"




On Wednesday, September 20, 2017 at 1:29:32 AM UTC-6, Idan Adar wrote:
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?

--
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/2b08c388-ccf5-43dd-a9a6-980eed34546f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Idan Adar
Thanks Robert. However I'm not sure yet how this helps in solving the next step here. Namely:

> How can I then use this in combination with: https://github.com/jansepar/node-jenkins-api#build_with_params
> ... the end goal is to trigger the job remotely with a parameter, and the parameter's value then needs to be used as an environment variable...

On Friday, September 22, 2017 at 6:42:35 AM UTC+3, Robert Hales wrote:
The Parameters can be defined in the pipeline, or in the job configuration, but if you define it in the pipeline, it will update the job configuration the first time it runs. So when you add the parameters to the pipeline, and have none configured in your job, your Build Now button will still be Build Now. Run it once, things may fail and die. But now your job will be configured with the parameters, and the Build Now link now says Build with Parameters. I think it is cleaner to add any config possible in the pipeline code. Also, if you change any property from the pipeline code, it will change all properties in the job config, so if it wasn't specified in the pipeline code, it will disable. So, for example, if you configure the build discarder in the project, then configure parameters in the pipeline code, you will lose your build discarder when the job runs. 

To access the parameters in your pipeline, use the params object: 

parameters {
   
string(defaultValue: 'master', description: 'Git Branch', name: 'gitBranch')
}


...


myProperty
= "${params.gitBranch}"




On Wednesday, September 20, 2017 at 1:29:32 AM UTC-6, Idan Adar wrote:
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?

--
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/8b4bed06-9b03-41cb-bee4-432bed087390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Robert Hales
You should be able to use the params object in the environment{} block and assign it to an environment variable.

--
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/a28ef2fa-f248-4f2e-a8af-30fa610d3b07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to pass paramater to process environment variable?

Slava Dubrovskiy
In reply to this post by Robert Hales

Hi Robert,

In case if I use Jenkinsfile in multibranch and simple pipeline jobs, and for simple pipeline jobs I would like to configure job's parameters manually and for multibranch jobs from Jenkinsfile. How can I do this?


22.09.2017 06:42, Robert Hales пишет:
The Parameters can be defined in the pipeline, or in the job configuration, but if you define it in the pipeline, it will update the job configuration the first time it runs. So when you add the parameters to the pipeline, and have none configured in your job, your Build Now button will still be Build Now. Run it once, things may fail and die. But now your job will be configured with the parameters, and the Build Now link now says Build with Parameters. I think it is cleaner to add any config possible in the pipeline code. Also, if you change any property from the pipeline code, it will change all properties in the job config, so if it wasn't specified in the pipeline code, it will disable. So, for example, if you configure the build discarder in the project, then configure parameters in the pipeline code, you will lose your build discarder when the job runs. 

To access the parameters in your pipeline, use the params object: 

parameters {
   
string(defaultValue: 'master', description: 'Git Branch', name: 'gitBranch')
}


...


myProperty
= "${params.gitBranch}"




On Wednesday, September 20, 2017 at 1:29:32 AM UTC-6, Idan Adar wrote:
The following is my current pipeline:

stage ("My Stage") {  
         environment
{
            cloudcerts_iamConfig_preprod
= credentials('${cloudcerts_iamConfig_preprod}')
         
}
             
         steps
{
               
// Setup packages and run tests
               sh
'''
                  npm install
                  npm test
               '''

         
}
}

During runtime of the tests, "cloudcerts_iamConfig_preprod" is available via process.env and everything is great.
My requirement now however is to add another property dynamically.

To do this I ticked the checkbox "This project is parameterized" > String parameter, and provided a name and default value (myStringParameter, "xxx").
I then added to "environments":

myProperty = ${myStringParameter)

However when the tests run process.env.myProperty returns "undefined".
Is this the right way to pass the parameter? Is there a different way?
--
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/2b08c388-ccf5-43dd-a9a6-980eed34546f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
WBD,
Viacheslav Dubrovskyi

--
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/7ec4cfc8-034b-0a02-dc2d-5e10785e7ad1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.