Environment Script Plugin

Skip to end of metadata
Go to start of metadata

Plugin Information

Plugin ID environment-script Changes In Latest Release
Since Latest Release
Latest Release
Latest Release Date
Required Core
1.2.2 (archives)
Nov 16, 2015
matrix-project (version:1.4)
Source Code
Issue Tracking
Pull Requests
Open Issues
Pull Requests
J��rgen P. Tjern�� (id: jorgenpt)
Dawid Malinowski (id: dawidmalina)
Usage Installations 2014-Nov 1373
2014-Dec 1364
2015-Jan 1468
2015-Feb 1535
2015-Mar 1676
2015-Apr 1731
2015-May 1799
2015-Jun 1788
2015-Jul 1843
2015-Aug 1930
2015-Sep 2074
2015-Oct 2165

Allows you to run a script before each build that generates environment variables for it.

Table of Contents


Environment Script Plugin allows you to have a script run after SCM checkout, before the build. If the script fails (exit code isn't zero), the build is marked as failed.
Any output on standard out is parsed as environment variables that are applied to the build. It supports "override syntax" to append paths to PATH-like variables (through EnvVars.override in Jenkins).

Some information about how it runs:

  • It runs after SCM checkout, so you can refer to files from your SCM of choice.
  • Matrix builds are supported, and the script runs on each of the build combinations (sub-builds, or whatever you call them), not on the 'master' flyweight task that kicks off the other ones.
  • It supports "override" (through EnvVars.override) syntax for appending to PATH-like variables: PATH+myuniqueidentifier=/foo is the same as PATH=$PATH:/foo in shell-script (notice the : is added automatically).
  • If you want to fail a build from the script, just exit with status code 1.
  • Support unix and windows scripts.


To enable this plugin, go to the configuration page of the job you care about, and check the box named Generate environment variables from script.

Regular job

In your script, just print "FOO=bar" to the standard output to set that variable.

echo VARIABLE1=Hello World

If you want to append to an existing PATH-style variable, you can do:

echo PATH+unique_identifier=/usr/local/bin

Otherwise, you're free to do whatever your heart desires in this script - cat a file, run a script in some other language from your project's source tree, etc.

Matrix job

Matrix jobs are pretty much the same as regular jobs, except you get a new checkbox: Run only on parent. If you enable this option, the script will only run on the matrix "parent" job, and not on the individual "configuration builds" (sub-builds). The environment variables will still be propagated to the children.

This option comes in handy if you need to do something like generate a shared version number based on a timestamp - the code will only run once, but all the different configurations will get the variable. Here's an example - note that ONLY $VERSION is seen by the jobs, not $base_version and $unix_time.

base_version=$(cat version.txt)
unix_time=$(date +%s)
echo VERSION=${base_version}-${unix_time}

Known issues

Version history

1.2.2 (Nov 16, 2015)

  • JENKINS-20705: Environment Script does not work on Windows Master.

1.2.1 (Nov 15, 2015)

  • JENKINS-30762: Environment script fails with job name shorter than 3 characters.
  • JENKINS-26673: Environment Script leaves files in /tmp on Ubuntu.

1.2 (Aug 28, 2015)

  • JENKINS-14754: Using a shebang was failing all builds.
  • Set the expected encoding of script output to UTF-8. PR
  • JENKINS-14951: Set environment on matrix parent build. PR
  • Bump jenkins core to 1.565
  • Add matrix-project as dependency
  • Add EnvironmentPluginAction to make exposing environment to build
  • Code formatting
  • Move junit to JenkinsRule

1.1.2 (Aug 9, 2012)

1.1.1 (Aug 8, 2012)

  • Add help for "Only run on parent" option.
  • Improve help for "Script content".
  • Use java.util.Properties to parse instead of our own crappy one.

1.1 (Aug 8, 2012)

  • JENKINS-14701: Added option to run script only on the 'parent' of a matrix build (instead of on each individual 'configuration build'),

1.0 (Aug 6, 2012)

  • First release.


plugin-buildwrapper plugin-buildwrapper Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.