Figure 10.3. Adding a parameter to the build job
10.2.2. Adapting Your Builds to Work with Parameterized Build Scripts
Once you have added a parameter, you need to configure your build scripts to use it. Choosing the
parameter name well is important here, as this is also the name of the variable that Jenkins will pass
through as an environment variable when it runs the build job. To illustrate this, consider the very basic
build job configuration in Figure 10.4, “Demonstrating a build parameter”, where we are simply echoing
the build parameter back out to the console. Note that, to make the environment variables more portable
across operating systems, it is good practice to put them all in upper case.
Figure 10.4. Demonstrating a build parameter
When we run this, we get a console output along the following lines:
Started by user anonymous
Building on master
[workspace] $ /bin/sh -xe /var/folders/y+/y+a+wZ-jG6WKHEm9KwnSvE+++TI/-Tmp-/
jenkins5862957776458050998.sh
+ echo Version=1.2.3
Version=1.2.3
Notifying upstream projects of job completion
Finished: SUCCESS
You can also use these environment variables from within your build scripts. For example, in an Ant or
Maven build, you can use the special env property to access the current environment variables:
<target name="printversion">
<property environment="env" />
<echo message="${env.VERSION}"/>
</target>