Contributing environment variables in a pipeline job

182 views
Skip to first unread message

Sridevi Sangaiah

unread,
Oct 5, 2016, 7:04:12 AM10/5/16
to jenkin...@googlegroups.com
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

Jesse Glick

unread,
Oct 5, 2016, 10:51:26 AM10/5/16
to Jenkins Dev
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<sridevi....@gmail.com> 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.

Jesse Glick

unread,
Oct 5, 2016, 10:55:46 AM10/5/16
to Jenkins Dev
On Wed, Oct 5, 2016 at 7:04 AM, Sridevi Sangaiah
<sridevi....@gmail.com> 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.

Sridevi Sangaiah

unread,
Oct 6, 2016, 2:52:06 AM10/6/16
to jenkin...@googlegroups.com
Thanks for the clarification, Jesse!


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 jenkinsci-dev+unsubscribe@googlegroups.com.
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.

Lakshmi Narasimhan

unread,
Dec 7, 2017, 2:02:58 AM12/7/17
to Jenkins Developers
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.

Jesse Glick

unread,
Dec 7, 2017, 11:06:58 AM12/7/17
to Jenkins Dev
On Thu, Dec 7, 2017 at 2:02 AM, Lakshmi Narasimhan
<vaikuntam....@gmail.com> 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.
Reply all
Reply to author
Forward
0 new messages