Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-32692

Access to environment variables set in workflow script in other plugins

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins 1.625.3, workflow-plugin 1.13, gerrit-trigger-plugin 2.18.2, envinject-plugin 1.92.1

      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.

            jglick Jesse Glick
            tmurtola Teemu Murtola
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: