This plugin contributes the keepEnv
step for Jenkins Pipelines. It is similar to the withEnv
step, but only retains environment variables that are defined in the argument, or are "system" environment variables.
It is similar in function to the "Keep Only Specified Environment Variables" option for some build steps introduced in Jenkins 2.248.
The following Pipeline demonstrates how this plugin works:
node { withEnv(['foo=bar', 'baz=qux', 'PATH=/usr/bin:/bin:/foo']) { sh 'env' keepEnv(['foo', 'WORKSPACE']) { sh 'env' } } }
-
The second invocation of
env
will not listbaz
or most Jenkins-contributed environment variables, likeBUILD_ID
orNODE_NAME
. -
The variables
foo
(from the surroundingwithEnv
block),WORKSPACE
(contributed by Jenkins), a few essential Jenkins-contributed variables, as well as system-contributed variables (likePATH
) will still be available. -
System-contributed environment variables that are not set to be kept will be reset to their default value (
PATH
in the example) instead of being undefined.
Report issues and enhancements in the Jenkins issue tracker.
Refer to our contribution guidelines
Licensed under MIT, see LICENSE