The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page.

For a list of other such plugins, see the Pipeline Steps Reference page.

Pipeline: Keep Environment Step Plugin

keepEnv: Keep only specified environment variables

Filters out for the scope of the block, the environment variables proposed by Jenkins except the ones listed. These are available to any external processes spawned within that scope. For example:

node {
  env.CUSTOM=test
  env.INFO=useful
  keepEnv(['INFO']) {
    // at this point the CUSTOM will not be available
    bat 'echo %INFO%'
  }
}

See the documentation for the env singleton for more information on environment variables.

  • variables : Array / List of String
    A list of environment variables to retain. Specify one variable name per line. All other environment variables added to the Pipeline by Jenkins will be removed from the block. System-contributed environment variables like PATH will be reset to their default value.

    Was this page helpful?

    Please submit your feedback about this page through this quick form.

    Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

        


    See existing feedback here.