I observe a strange behavior when trying to make a Jenkins project which has Ant steps accepting any String parameters to use by Ant. It so looks that Ant somehow receives some malformed content as parameters.
First I logged on the same system Jenkins installed on and wrote a simple ant build file:
<?xml version="1.0"?>
<!--DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "/usr/src/ant/project.dtd"-->
<project name="many-params" default="run">
<target name="run">
<echo message="first Param: ${firstparam}"/>
<echo message="second Param: ${secondparam}"/>
</target>
</project>
I then ran the ant with parameters set and got the expected output:
$ ant -Dfirstparam=A -Dsecondparam=B
Buildfile: /tmp/build-dir/build.xml
run:
[echo] first Param: A
[echo] second Param: B
BUILD SUCCESSFUL
Total time: 0 seconds
Next up, I went to setting a project doing the same in Jenkins. My Jenkins systems specs follow:
- OS: Linux amd64 2.6.32-504.1.3.el6.x86_64
- Jenkins: ver. 1.618
- JRE Jenkins is running on: Oracle 1.7.0_55-b13
- Ant Plugin Version: 1.2
- JRE Used for the Project: Oracle 1.6.45 32-bit
- Ant Used for the Project: 1.8.2
I have set up the job of 8 consecutive steps, 4 preparatory shell script pieces that rewrite build.xml with slightly different parameter names (no separators, dash separators, dot separators) and 4 Ant build steps that call ant, trying to pass the corresponding parameters.
The ready config.xml from the job directory looks like:
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>A simple task to test many parameter setting for jenkins calling ant tasks</description>
<logRotator class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>10</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>-1</artifactNumToKeep>
</logRotator>
<keepDependencies>false</keepDependencies>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>Oracle Java 1.6.45 32-bit JRE</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>echo "STEP 1: Pass parameters with no separators in names"
cat > build.xml << EOF
<?xml version="1.0"?>
<!--DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "/usr/src/ant/project.dtd"-->
<project name="many-params" default="run">
<target name="run">
<echo message="first Param: ${paramfirst}"/>
<echo message="second Param: ${paramsecond}"/>
</target>
</project>
EOF</command>
</hudson.tasks.Shell>
<hudson.tasks.Ant plugin="ant@1.2">
<targets>run</targets>
<antName>Ant 1.8.2</antName>
<properties>paramfirst=A
paramsecond=B</properties>
</hudson.tasks.Ant>
<hudson.tasks.Shell>
<command>rm build.xml
echo
echo "STEP 2: Pass parameters with separated by dashes in names"
cat > build.xml << EOF
<?xml version="1.0"?>
<!--DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "/usr/src/ant/project.dtd"-->
<project name="many-params" default="run">
<target name="run">
<echo message="first Param: ${param-first}"/>
<echo message="second Param: ${param-second}"/>
</target>
</project>
EOF</command>
</hudson.tasks.Shell>
<hudson.tasks.Ant plugin="ant@1.2">
<targets>run</targets>
<antName>Ant 1.8.2</antName>
<properties>param-first=A
param-second=B</properties>
</hudson.tasks.Ant>
<hudson.tasks.Shell>
<command>echo
echo "STEP 3: Same, but with parameters on the same line in Ant Plugin step setup"</command>
</hudson.tasks.Shell>
<hudson.tasks.Ant plugin="ant@1.2">
<targets>run</targets>
<antName>Ant 1.8.2</antName>
<properties>param-first=A param-second=B</properties>
</hudson.tasks.Ant>
<hudson.tasks.Shell>
<command>rm build.xml
echo
echo "STEP 4: Pass parameters with separated by dots in names"
cat > build.xml << EOF
<?xml version="1.0"?>
<!--DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "/usr/src/ant/project.dtd"-->
<project name="many-params" default="run">
<target name="run">
<echo message="first Param: ${param.first}"/>
<echo message="second Param: ${param.second}"/>
</target>
</project>
EOF</command>
</hudson.tasks.Shell>
<hudson.tasks.Ant plugin="ant@1.2">
<targets>run</targets>
<antName>Ant 1.8.2</antName>
<properties>param.first=A
param.second=B</properties>
</hudson.tasks.Ant>
</builders>
<publishers/>
<buildWrappers>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup@0.26">
<deleteDirs>false</deleteDirs>
<cleanupParameter></cleanupParameter>
<externalDelete></externalDelete>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
</buildWrappers>
</project>
Building the task gave me the following output:
Started by user Alexander Krasnyansky
[EnvInject] - Loading node environment variables.
Building remotely on j03_uk1ps41 (buildslaves) in workspace /var/lib/jenkins03/workspace/akrasnyansky/ManyParams/ant-param-test
Deleting project workspace... done
[ant-param-test] $ /bin/sh -xe /tmp/hudson2203137136163442442.sh
+ echo 'STEP 1: Pass parameters with no separators in names'
STEP 1: Pass parameters with no separators in names
+ cat
[ant-param-test] $ /usr/local/apache-ant-1.8.2/bin/ant -Dparamfirst=A -Dparamsecond=B run
Buildfile: /var/lib/jenkins03/workspace/akrasnyansky/ManyParams/ant-param-test/build.xml
run:
[echo] first Param:
[echo] second Param:
BUILD SUCCESSFUL
Total time: 0 seconds
[ant-param-test] $ /bin/sh -xe /tmp/hudson5869719507232196626.sh
+ rm build.xml
+ echo
+ echo 'STEP 2: Pass parameters with separated by dashes in names'
STEP 2: Pass parameters with separated by dashes in names
+ cat
[ant-param-test] $ /usr/local/apache-ant-1.8.2/bin/ant -Dparam-first=A -Dparam-second=B run
Buildfile: /var/lib/jenkins03/workspace/akrasnyansky/ManyParams/ant-param-test/build.xml
run:
[echo] first Param: first
[echo] second Param: second
BUILD SUCCESSFUL
Total time: 0 seconds
[ant-param-test] $ /bin/sh -xe /tmp/hudson1052316660761572548.sh
+ echo
+ echo 'STEP 3: Same, but with parameters on the same line in Ant Plugin step setup'
STEP 3: Same, but with parameters on the same line in Ant Plugin step setup
[ant-param-test] $ /usr/local/apache-ant-1.8.2/bin/ant "-Dparam-first=A param-second=B" run
Buildfile: /var/lib/jenkins03/workspace/akrasnyansky/ManyParams/ant-param-test/build.xml
run:
[echo] first Param: first
[echo] second Param: second
BUILD SUCCESSFUL
Total time: 0 seconds
[ant-param-test] $ /bin/sh -xe /tmp/hudson4427994032931026249.sh
+ rm build.xml
+ echo
+ echo 'STEP 4: Pass parameters with separated by dots in names'
STEP 4: Pass parameters with separated by dots in names
+ cat
/tmp/hudson4427994032931026249.sh: line 5: <?xml version="1.0"?>
<!--DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "/usr/src/ant/project.dtd"-->
<project name="many-params" default="run">
<target name="run">
<echo message="first Param: ${param.first}"/>
<echo message="second Param: ${param.second}"/>
</target>
</project>
: bad substitution
Build step 'Execute shell' marked build as failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE
So this arises many questions:
- Why no values are printed at all at STEP 1?
- How it came to using string values "first" and "second" instead of "A" and "B" I supplied at STEP 2?
- Why at STEP 3 malformed line "-Dparam-first=A param-second=B" (produced by putting both parameters on the same line in Jenkins step setup: param-first=A param-second=B) works just as well as "-Dparam-first=A -Dparam-second=B" at STEP 2? I was supposed to fail here, as happens when I run the same in the shell.
- What is wrong with the dots at STEP 4? Why does it produce a bad substitution error here?
Many thanks for any advise on these issues.