Class EnvironmentInjector

    • Method Detail

      • inject

        public static void inject​(Run<?,​?> run,
                                  EnvVars envVars,
                                  String name,
                                  Object value)
        Deprecated.
        Add an environment variable binding for the given Run.

        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.

        Parameters:
        run - the run object
        envVars - the current set of EnvVars which needs to be updated at the same time
        name - the variable name
        value - the variable value
        See Also:
        EnvironmentInjector.CustomEnvironmentContributor, JENKINS-29537