{excerpt}This plugin makes it possible to have an isolated environment for your jobs.{excerpt}

h1. Features

* Removes inherited environment variables by the Jenkins Java process
* Injects environment variables at node (master/slave) startup
* Executes a setup script before or/and after a SCM checkout for a run
* Injects environment variables before or/and after a SCM checkout for a run
* Injects environment variables as a build step for a run
* Injects password values for a run
* Exports environment variables at the end of the build in order to to know the set of environment variables used for each build

h1. Some use cases

* To remove inherited environment variables (PATH, ANT_HOME, ...) at node level (master/slave), available by default for a job run.
* To inject variables in the first step of the job (before the SCM checkout)
* To inject variables based on user parameter values
* To execute an initialization script before a SCM checkout.
* To execute an initialization script after a SCM checkout
* To inject variables as a build step obtained from a file filled in by a previous build step
* To know environment variables used for a build
* To inject build cause as environment variable for a build
* To inject environment variables from the evaluation of a Groovy script
* To export environment variables as a metadata in your binary repository

h1. Configuration

h2. At node (master and slaves) level


h2. At job level

h3. Set up a clean environment


h3. Inject variables after a SCM checkout


h3. Inject variables as a build step


h1. Variables Traceability

Each build captures environment variables and stores them in an environment file called 'injectedEnvVars.txt' located in

For an old build, you can display injected environment variables through the right UI menu on the build page.

You can also get build environment variables by the following HTTP GET URL: <jenkins_url>/job/<job_name>/<build_number>/injectedEnvVars/export
XML, JSON and TXT format are supported.
For example:
* curl \-X GET H"Accept:text/plain" <jenkins_url>/job/<job_name>//lastBuild/injectedEnvVars/export
* curl \-X GET H"Accept:application/xml" <jenkins_url>/job/<job_name>//18/injectedEnvVars/export
* curl \-X GET H"Accept:application/json" <jenkins_url>/job/<job_name>//18/injectedEnvVars/export

h1. Examples

h2. Append to PATH on Windows


Gerrit Trigger plugin with parameterized Build branch name
Check "Prepare an environment for the run"
Evaluated Groovy script:
if (\!binding.variables.containsKey('GERRIT_REFSPEC')) {
&nbsp; &nbsp; return \[GERRIT_REFSPEC: "refs/heads/$GERRIT_BRANCH"\]

h3. Gerrit Trigger plugin with parameterized Build branch name

* Check "*Prepare an environment for the run*"
** *Evaluated Groovy script*:
if (!binding.variables.containsKey('GERRIT_REFSPEC')) {
    return [GERRIT_REFSPEC: "refs/heads/$GERRIT_BRANCH"]

h1. Additional features provided by other plugins

[Shared Objects|JENKINS:SharedObjects Plugin] plugin contributes to Envinject plugin that enables you to populate shared objects as environment variables.

h1. EnvInject and interactions with other plugins

EnvInject captures build environment variables populated by plugins providing environment variables through Jenkins extension points (such as BuildWrappers, EnvironmentContributions and so on).
Environment variables injected by the EnvInject plugin are available in Jenkins triggers (for example in all [XTrigger plugin|JENKINS:XTrigger Plugin] typologies, injected environment variable can be used).
Injected environment variables with the EnvInject plugin are captured by the [BuildContext capture plugin|JENKINS:BuildContextCapture Plugin].

h1. Comparison with other plugins

This plugin is an alternative to [JENKINS:Setenv Plugin] and [JENKINS:Envfile Plugin] plugins
Note 1: The EnvInject plugin automatically migrates the Jobs configuration from these plugins. The setenv and/or the envfile plugins can be deleted from your plugin list.
Note 2: Master and slave are managed.

h1. Jenkins core compatibility

This plugin requires Jenkins 1.410\+

h1. Changelog

h2. 1.62

\* Fix [14371@issue] \- NullPointerException in EnvInjectBuilderContributionAction.buildEnvVars during SCM poll

h2. 1.61

\* Fix [14367@issue] \- Global & node level self-referencing variables should work

h2. 1.60

\* Fix [14290@issue] \- Support for Ivy project type

h2. 1.59

\* Fix [14271@issue] \- EnvInject claims global env vars are unresolved on slave

h2. 1.58

\* Fix [14284@issue] \- Single backslashes are droped or used as escape char

h2. 1.57

\* Fix [14232@issue] \- EnvInject not handling properties file with logical lines

h2. 1.56

\* Load environment variables from the node (therefore, you are able to redefine classic variables such as the PATH variable at node level)
\* Upgrade to envinject-lib 1.8

h2. 1.55

\* Technical release: Merge pull request - Make EnvInjectPluginAction implements EnvironmentContributingAction

h2. 1.54

\* A few minor changes to keep jdk5 compatibility

h2. 1.53

\* Fix regression on backward compatibility

h2. 1.52

\* Remove env variables presence in build serialization file

h2. 1.51

\* Add a complement to fix [12423@issue] \- Password masked by Mask Passwords are visible when using envinject plugin (no display environment variables when the job is running)

h2. 1.50

\* Update to envinject-lib 1.7 (Enable to external plugin to retrieve envVars)

h2. 1.49

\* Merge pull request - use UnsupportedOperationException instead of UnsupportedMediaException
\* Merge pull request - added Japanese localization

h2. 1.48

\* Fix [12878@issue] \- manage old data fails with RuntimeException: Failed to serialize hudson.model.Actionable#actions for class hudson.model.FreeStyleBuild

h2. 1.47

\* Fix [13566@issue] \- EnvInject is messing around with my TEMP variable when username contains a dollar sign (windows)
\* Update to envinject-lib 1.5

h2. 1.46

\* Fix interaction with multijob plugin

h2. 1.45

\* Add /export/txt, /export/xml and /export/json for the exportation

h2. 1.44

\* Fix EnvInject Password process

h2. 1.43

\* Fix reopened [12108@issue] \- EnvInject failure using multi-configuration jobs

h2. 1.42

\* Fix [13183@issue] \- SCM variables resolution

h2. 1.41

\* Fix [13157@issue] \- EnvInject cannot inject variables whose contents contain a dollar sign ($)

h2. 1.40

\* Fix [13167@issue] \- Cannot use EnvInject in a Maven 2 Jenkins project

h2. 1.39

\* Fix [13155@issue] \- Parameters are not working in EnvInject plugin 1.38

h2. 1.38

\* Fix [13119@issue] \- Add feature: Set an environment variable based on value of user passed parameter

h2. 1.37

\* Fix [13085@issue] \- Environment Variable Injection doesn't work when project run on slave node that sets the same variable

h2. 1.36

\* Fix [13041@issue] \- PATH variable is being injected from master on multiconfiguration jobs

h2. 1.35

\* Fix [13022@issue] \- EnvInject 1.33 doesn''t seem to work with Jenkins 1.454

h2. 1.34

\* Change Environment contributors resolution

h2. 1.33

\* Move global passwords injection to the 'Prepare job environment' section
\* Add 'Inject job passwords'

h2. 1.32

\* Fix [12944@issue] \- Env Inject Plugin doesn't substitute $\{WORKSPACE\} variable at all when used in 'Preparing an environment for the job'
\* Fix [12963@issue] \- EnvInject plugin causes job to use JAVA_HOME instead of configured JDK

h2. 1.31

\* Fix [12936@issue] \- EnvInject Plugin 1.30 does not display all properties on job config page

h2. 1.30

\* Fix [12905@issue] \- PATH variable is not injected

h2. 1.29

\* Fix [12876@issue] \- Version 1.20 and later removed all comments and new-lines
\* Add test to [12841@issue] \- EnvInject Plugin 1.26 does not substitute $\{WORKSPACE\} correctly

h2. 1.28

\* Fix reponed [12108@issue] \- EnvInject failure using multi-configuration jobs
\* Fix [12841@issue] \- EnvInject Plugin 1.26 does not substitute $\{WORKSPACE\} correctly

h2. 1.27

\* Add a build context to EnvInjectContributor

h2. 1.26

\* Fix [12704@issue] \- WORKSPACE variable for concurrent builds are not defined properly.

h2. 1.25

\* Fix [12809@issue] \- Injecting from file removes backslashes on $\{WORKSPACE\}

h2. 1.24

\* Add the ability to inject password values
\* Fix [12423@issue] \- Password masked by Mask Passwords are visible when using envinject plugin

h2. 1.23

\* Fix [12788@issue] \- Missing variables when executing EnvInject script

h2. 1.22

\* Fix NullPointerException for a setenv or a envfile migration

h2. 1.21

\* Fix [12746@issue] \- envinject strips off "\" each time config page is opened

h2. 1.20

\* Move properties content serialization to a Map (avoid carriage return issues)
\* Fix usage of build variables for the 'Prepare environment jobs'
\* Fix Injected environment vars when EnvInject is not configured

h2. 1.19

\* Fix reopened [12423@issue] \- Password masked by Mask Passwords are visible when using envinject plugin

h2. 1.18

\* Fix [12691@issue] \- Property variable not set if using a property file

h2. 1.17

\* Fix migration from the setenv and envfile plugin

h2. 1.16

\* Fix external EnvInjectContribution section display
\* Fix text typo

h2. 1.15 (technical release)

\* Refactoring + fix wrong commit

h2. 1.14

\* Fix [12416@issue] \-  Environment is not injected for each configuration in a multi-configuration project

h2. 1.13

\* Add the extension point EnvInject Job Property Contributor to enable other plugins to contribute to this plugin for the prepare job step

h2. 1.12

\* Fix [12423@issue] \- Password masked by Mask Passwords are visible when using envinject plugin

h2. 1.11

\* Update to envinject-lib 1.2

h2. 1.10

\* Update to envinject-lib 1.1
\* Fix bug on the build end

h2. 1.9

\* Export reuse code to a dedicated library: envinject-lib 1.0
\* Fix typo

h2. 1.8

\* Switch properties section and scripts section for the prepare step

h2. 1.7

\* Fix [12293@issue] \- Incorrect inserting environment variables on linux slave

h2. 1.6

\* Recording EnvVars contributing by other plugins at the end of the build

h2. 1.5

\* Fix [12252@issue] \- envinject does not fail the build after Environment Script Content fails

h2. 1.4

\* Fix portability in the history build.xml file (using the build reference instead of the absolute path of the EnvInjected file)
\* Add the ability to load a properties file at node startup (at master and/or at slave startup)

h2. 1.3

\* Move 'Triggered Build Cause' to Jenkins build variables option
\* Add an export option to export environment variables to TXT, XML or JSON

h2. 1.2

\* Fix NullPointerException when master has 0 executors

h2. 1.1

\* Fix [12108@issue] \- EnvInject failure using multi-configuration jobs
\* Fix [12084@issue] \-Variables resolved alphabetically rather than order found in content/file. $\{WORKSPACE\} not always getting resolved as result
\* Accept script parameters to script path sections

h2. 1.0

\* Fix [12027@issue] \- $\{WORKSPACE} variable doesn't use my specific workspace directory anymore in a build step
\* Make it stable for production

h2. 0.26

\* Enhance display log
\* Refactoring for fixing properties variables propagation

h2. 0.25

\* Fix [11763@issue] \- Can not set some 'special' variable names the first time
\* Technical Refactoring

h2. 0.24

\* Make it extensible by an another plugin.

h2. 0.23

\* Fixed [11595@issue] \- Some env variables can not be used to inject, for example $NODE_NAME

h2. 0.22

\* Add the ability for the 'prepare environment' feature to load the properties file and the script file from the master node even if the build runs on a slave node.

h2. 0.21

\* Add global properties and node properties process

h2. 0.20

\* Fix [11439@issue] \- Can't add "environment inject" to [pre-scm-buildstep|JENKINS:pre-scm-buildstep] plugin.

h2. 0.19

\* Fix [11181@issue] \-Variables failing to be set if referencing previous variable

h2. 0.18

\* Fix [11067@issue] \- Pre-SCM and Post-SCM environment scripts do not use Pre-SCM and Post-SCM properties

h2. 0.17

\* Fix [11066@issue] \- Property Variables "Randomly" Not Working/Getting Unset

h2. 0.16

\* Fix [11063@issue] \- Multiple "Inject Environment Variables" Build Steps All Show Same Content

h2. 0.15

\* Backslashes in file path for windows platform are managed
\* Added feature 'unset variable' when the variable is unresolved

h2. 0.14

\* Integrate domi pull request (add trigger causes as environment variables)
\* Fix [10980@issue] \- EnvInject to optinally trim trailing spaces

h2. 0.13.1

\* Improve reporting errors

h2. 0.13

\* Fix [10919@issue] \- Variables are shared between jobs

h2. 0.12

\* Fixed [10916@issue] \- Properties not injected and build marked as failed

h2. 0.11.1 (technical release)

\* Remove unused maven dependency

h2. 0.11

\* Fix [10894@issue] \- Inject environment variables with property file not working

h2. 0.10

\* Add the ability to unset system variable at node level
\* Add an option to 'Keep Jenkins system variables'
\* Fix [10845@issue] and [10877@issue] \- master/slave sync / Job variables/parameters are missing
\* Complete the fix to [10847@issue]

h2. 0.9

\* Fix partially [10847@issue] and [10845@issue] \- Enivronment is not separated
\* The ability to 'Keep system variables' has been removed. The feature will be restored later (and moved at slave/node level (not at job level).

h2. 0.8

\* Fixed variables restauration for Maven jobs

h2. 0.7

\* Fixed variables propagation between typologies
\* Fixed variables restore for all typologies

h2. 0.6

\* Add a 'Keep Jenkins Build variables' option
\* Add 'EnvInject' as prefix for plugin log messages
\* Sort the EnvInject variables table

h2. 0.5

\* Remove advanced sections

h2. 0.4

\* Add a build wrapper
\* Fix serialization fiels for JobProperty
\* Add a migration procedure for setenv and envfile plugins

h2. 0.3

\* Add variables resolution in elements

h2. 0.2.1

\* Fix environment script content process

h2. 0.2

\* Can inject environment variables as a build step.

h2. 0.1

\* Initial version