Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a workflow step access environment variables provided by an EnvironmentContributingAction?

A custom plugin we wrote for an older version of Jenkins uses an EnvironmentContributingAction to provide environment variables to the execution so they could be used in future build steps and passed as parameters to downstream jobs.

While attempting to convert our build to workflow, I'm having trouble accessing these variables:

node {
    // this step queries an API and puts the results in
    // environment variables called FE1|BE1_INTERNAL_ADDRESS
    step([$class: 'SomeClass', parameter: foo])

    // this ends up echoing 'null and null'
    echo "${env.FE1_INTERNAL_ADDRESS} and ${env.BE1_INTERNAL_ADDRESS}"
}

Is there a way to access the environment variable that was injected? Do I have to convert this functionality to a build wrapper instead?

like image 656
SaucyWrong Avatar asked Oct 31 '25 14:10

SaucyWrong


1 Answers

EnvironmentContributingAction is currently limited to AbstractBuilds, which WorkflowRuns are not, so pending JENKINS-29537 which I just filed, your plugin would need to be modified somehow. Options include:

  • Have the builder add a plain Action instead, then register an EnvironmentContributor whose buildEnvironmentFor(Run, …) checks for its presence using Run.getAction(Class).
  • Switch to a SimpleBuildWrapper which defines the environment variables within a scope, then invoke it from Workflow using the wrap step.
  • Depend on workflow-step-api and define a custom Workflow Step with comparable functionality but directly returning a List<String> or whatever makes sense in your context. (code sample)
like image 100
Jesse Glick Avatar answered Nov 02 '25 10:11

Jesse Glick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!