[JIRA] [workflow-plugin] (JENKINS-32692) Access to environment variables set in workflow script in other plugins

2 views
Skip to first unread message

teemu.murtola@gmail.com (JIRA)

unread,
Jan 30, 2016, 10:27:02 AM1/30/16
to jenkinsc...@googlegroups.com
Teemu Murtola created an issue
 
Jenkins / Improvement JENKINS-32692
Access to environment variables set in workflow script in other plugins
Issue Type: Improvement Improvement
Assignee: Jesse Glick
Components: workflow-plugin
Created: 30/Jan/16 3:26 PM
Environment: Jenkins 1.625.3, workflow-plugin 1.13, gerrit-trigger-plugin 2.18.2, envinject-plugin 1.92.1
Priority: Minor Minor
Reporter: Teemu Murtola

There should be a way to access environment variables set within the workflow script from other plugins, from code that executes outside the Groovy script.

My particular case is that I want to compute a value for an environment variable within the workflow Groovy script, and then use that value in Gerrit Trigger configuration to customize how the plugin reports the results back to Gerrit (in this case, the URL to post back). Gerrit Trigger uses Run.getEnvironment() to do replacements in the configuration values I want, and in a freestyle project, I can use EnvInject plugin to inject environment variables that then get expanded there. But in a workflow build, values assigned to env.FOO are not visible to Gerrit Trigger, and I could not find any other way to achieve this, either.

I'm not an expert in Jenkins internals, but by looking at the code of the various plugins, it looks like it could be straightforward to provide an EnvironmentContributor from the workflow plugin that would expose the variables set through env also through Run.getEnvironment(). There are probably other ways of doing this as well, but this way should not require other plugins to depend on workflow-plugin constructs. And probably all other EnvInject plugin functionality is already covered by the workflow plugin.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.2#64017-sha1:e244265)
Atlassian logo

jglick@cloudbees.com (JIRA)

unread,
Feb 1, 2016, 2:56:01 AM2/1/16
to jenkinsc...@googlegroups.com
Jesse Glick commented on Improvement JENKINS-32692
 
Re: Access to environment variables set in workflow script in other plugins

Your case would perhaps be better handled by JENKINS-26103, though I am not familiar with the details.

An EnvironmentContributor might be a general solution though it would require some careful refactoring of the already brittle environment variable handling.

teemu.murtola@gmail.com (JIRA)

unread,
Feb 1, 2016, 11:02:03 AM2/1/16
to jenkinsc...@googlegroups.com

Yes, a way to directly interact with Gerrit Trigger from the workflow would provide another solution, but JENKINS-26103 by itself would not provide a perfect solution for us: we have multiple Jenkins jobs that trigger on the same Gerrit event, and Gerrit Trigger automatically combines the posts back to Gerrit such that there is only one post, once all the builds finish. For now, we would probably just want to move one of these jobs to a workflow, and still keep this reporting otherwise functional. So intermediate voting as mentioned in that issue would not be ideal.

What could work is that if instead of JENKINS-26103, Gerrit Trigger provided a mechanism to influence the final post from within the workflow. That would probably be a good long-term solution for our case. EnvironmentContributor could be more general, but I'm not sure how many other plugins would actually benefit from it.

jglick@cloudbees.com (JIRA)

unread,
Aug 29, 2016, 4:23:01 PM8/29/16
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
 
Change By: Jesse Glick
Component/s: workflow-cps-plugin
Component/s: pipeline
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

nthienan.it@gmail.com (JIRA)

unread,
Sep 18, 2019, 5:11:02 AM9/18/19
to jenkinsc...@googlegroups.com
An Nguyen commented on Improvement JENKINS-32692
 
Re: Access to environment variables set in workflow script in other plugins

I'd love to see this is implemented although my use case is different.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

nthienan.it@gmail.com (JIRA)

unread,
Sep 18, 2019, 5:40:02 AM9/18/19
to jenkinsc...@googlegroups.com
An Nguyen edited a comment on Improvement JENKINS-32692
Reply all
Reply to author
Forward
0 new messages