Pass environment variables to Ant build.xml from Jenkins?

user755806 picture user755806 · Jul 18, 2014 · Viewed 19.5k times · Source

I am using Jenkins as CI. I have an build.xml. Build.xml has code like below.

<property name="environment" value="$environment}" />

How can i pass value to build.xml from Jenkins ? Can i pass it through environment variables?

Answer

Straff picture Straff · Jan 28, 2015

Your environment variables are available via the environment property. In the example below, the environment variable VIEW is printed from the simple hello world ant script via ${env.VIEW}. Change VIEW to the name of the environment variable of interest.

<?xml version="1.0" encoding="UTF-8"?>
<project name="Hello World" default="Hello" basedir=".">
    <property environment="env"/>
    <property name="HelloText" value="Hello"/>
    <target name="Hello">
        <echo>VIEW=${env.VIEW}</echo>
    </target>
</project> 

IMPORTANT! Note that this line is needed in order for env.VIEW to be understood by ant:

<property environment="env"/>