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?
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?
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"/>
If your ant build dependeds on the property environment
:
<property
name="environment"
value="a_value_I_edit_just_before_run_ant_default_target_mannually" />
you could configure your Jenkins' job to build with parameter:
so Jenkins will log (i.e. on Windows) something like:
cmd.exe /C '"ant.bat ant -file build.xml -Djenkins_environment=myValue && exit %%ERRORLEVEL%%"'
Then you could modify your ant build to check for system property:
<property
name="manually_edited_environment"
value="a_value_I_edit_just_before_run_ant_default_target_manually" />
<condition property="environment"
value="${jenkins_environment}"
else="${manually_edited_environment}">
<isset property="jenkins_environment" />
</condition>
if the jenkins_environment
property is set then environment
gets its value, else environment
gets manually_edited_environment
's value; the remaining part of your build still depend on the property environment
.
If you have trouble in correctly matching the -DpropertyName
use the echoproperties ant task to make ant logging all system properties.
your ant script should look like this:-
<target name="test" >
<property environment="env" />
<echo>BUILD_NUMBER: ${env.BUILD_NUMBER}</echo>
</target>
You can set properties with build parameters (ie: myParameter) and get them in an ant script with ${myParameter}
.
Just make sure you don't use dots in parameters names in jenkins because there might be problems getting them in the ant script.
As for environment variables, i don't know, sorry.