@Deprecated public final class EnvironmentInjector extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
EnvironmentInjector.CustomEnvironmentContributor
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
inject(hudson.model.Run<?,?> run,
hudson.EnvVars envVars,
String name,
Object value)
Deprecated.
Add an environment variable binding for the given Run.
|
public static void inject(hudson.model.Run<?,?> run,
hudson.EnvVars envVars,
String name,
Object value)
The EnvironmentContributingAction is more preferred for the environment variable injection.
However, is not compatible with workflow at the time of implementation.
We register the EnvironmentInjector.CustomEnvironmentContributor which scans for private
EnvironmentInjectionAction bound to the Run instance, and updates the environment variables
accordingly. This will be called by Run.getEnvironment(TaskListener).
In pipeline, the EnvVars should be fetched from StepContext#get(EnvVars.class), and it will
not contain the changes to the environment variables bound to the Run object. In that case we should
modify the EnvVars returned from StepContext#get(EnvVars.class). Passing it as the second
parameter of this method.
Note that Run.getEnvironment(TaskListener) returns a snapshot of the environment variables. If new
variables are injected, we need to call it again to get the latest values. Or if you have a snapshot of the
EnvVars, pass it as the second parameter so that it gets updated at the same time.
run - the run objectenvVars - the current set of EnvVars which needs to be updated at the same timename - the variable namevalue - the variable valueEnvironmentInjector.CustomEnvironmentContributor,
JENKINS-29537Copyright © 2016–2018. All rights reserved.