Contributing environment variables in a pipeline job

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

Contributing environment variables in a pipeline job

Sridevi Sangaiah
I am part of the team maintaining the Team Concert plugin for Jenkins - https://wiki.jenkins-ci.org/display/JENKINS/Team+Concert+Plugin.

We are seeing a restriction with accessing the env object in pipeline scripts. We contribute environment variables to a run. If the env object is not accessed before SCM checkout runs, then accessing the environment variables contributed by the Team Concert plugin, returns the appropriate values. But if the env object is accessed before the checkout runs, then accessing the environment variables contributed by the Team Concert plugin, even after checkout runs, always return null.

For example, assuming that the Team Concert plugin contributes the environment variable "TC_ENV_VAR1". Then the following script returns the value set by the Team Concert plugin, for TC_ENV_VAR1.

    checkout(<scm_parameters>)
    echo "${env.TC_ENV_VAR1}"

But the following script returns a null value for "TC_ENV_VAR1"
   
    echo "${env.BUILD_NUMBER}"
    checkout(<scm_parameters>)
    echo "${env.TC_ENV_VAR1}"
   
We contribute environment variables through an implementation of hudson.model.EnvironmentContributor.

Could there be any additional implementation that is required to invalidate or refresh the environment variables, in case the env object was already constructed?

Thanks & Regards,
Sridevi

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CADM3cT76C%2BYff0XBx3uEpiL-OqOis5%3Dnk06hD71NWsKTfWq3yg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Contributing environment variables in a pipeline job

Jesse Glick-4
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<[hidden email]> wrote:
> We contribute environment variables through an implementation of
> hudson.model.EnvironmentContributor.

Pipeline does not currently support retrieval of environment variables
from SCM checkouts. Cf. JENKINS-26100.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr0pxYSiZv9nHRtUMFDmiqx2zLs1VAy9WGO_meh_90eQ4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Contributing environment variables in a pipeline job

Jesse Glick-4
In reply to this post by Sridevi Sangaiah
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<[hidden email]> wrote:
> Could there be any additional implementation that is required to invalidate
> or refresh the environment variables, in case the env object was already
> constructed?

And yes `env` caches variables after first use, to avoid performance
problems. There is not currently any provision to rerun
`EnvironmentContributor`s, nor any API in Jenkins for such
contributors to indicate that their result might have changed since
the last call.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr3JpWMd13mJSEJBuWke4ZS59_LaYB3Hr8yrC%2Bigf9zgoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Contributing environment variables in a pipeline job

Sridevi Sangaiah
Thanks for the clarification, Jesse!


Regards,
Sridevi

On Wed, Oct 5, 2016 at 8:25 PM, Jesse Glick <[hidden email]> wrote:
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<[hidden email]> wrote:
> Could there be any additional implementation that is required to invalidate
> or refresh the environment variables, in case the env object was already
> constructed?

And yes `env` caches variables after first use, to avoid performance
problems. There is not currently any provision to rerun
`EnvironmentContributor`s, nor any API in Jenkins for such
contributors to indicate that their result might have changed since
the last call.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr3JpWMd13mJSEJBuWke4ZS59_LaYB3Hr8yrC%2Bigf9zgoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CADM3cT4Pa3_AGDbE7Ud6nBh4%3D4DvhoC6TzefLBHKTY8OHWKV0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Contributing environment variables in a pipeline job

Lakshmi Narasimhan Vaikuntam
In reply to this post by Jesse Glick-4
Hi Jesse,

I tried the pipeline script in first comment in Jenkins 2.73.3 and I was able to get back the environment variable contributed by Team Concert Plugin's Environment Contributor.  It appears that env is getting rebuilt. Could you confirm this? Also it will help if you could provide the Jenkins issue through which this was fixed.

On Wednesday, October 5, 2016 at 8:25:46 PM UTC+5:30, Jesse Glick wrote:
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4BzWXd3cAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sridevi....@...> wrote:
> Could there be any additional implementation that is required to invalidate
> or refresh the environment variables, in case the env object was already
> constructed?

And yes `env` caches variables after first use, to avoid performance
problems. There is not currently any provision to rerun
`EnvironmentContributor`s, nor any API in Jenkins for such
contributors to indicate that their result might have changed since
the last call.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/661205a8-7a53-437d-8c58-3c65c13ba26c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Contributing environment variables in a pipeline job

Jesse Glick-4
On Thu, Dec 7, 2017 at 2:02 AM, Lakshmi Narasimhan
<[hidden email]> wrote:
> I tried the pipeline script in first comment in Jenkins 2.73.3 and I was
> able to get back the environment variable contributed by Team Concert
> Plugin's Environment Contributor.  It appears that env is getting rebuilt.
> Could you confirm this?

Jenkins version is irrrelevant. Depends on whether you are running
`workflow-cps` 2.40+, with the fix of JENKINS-42499, or older, which
still had the cache.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr1t0b_p%2B39A%3D02P-gReMnhMMVHyp9weHARbcFEFkMiWJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.