-
Bug
-
Resolution: Fixed
-
Blocker
-
None
-
Hudson 1.376 on Windows 2003 Server with Tomcat 6.
-
Powered by SuggestiMate
If Ant build steps take properties with an %, the next char is enclosed in quotes in a 'fancy' way:
$ cmd.exe /C '"C:\ant\apache-ant-1.7.1\bin\ant.bat "-Dhudsonhome=%"H"UDSON_HOME%" && exit %%ERRORLEVEL%%"'
The property should be "-Dhudsonhome=%HUDSON_HOME%"
This worked with Hudson 1.365
- is related to
-
JENKINS-7657 Ant properties escaping breaks url parameter for jsunit build
-
- Resolved
-
-
JENKINS-7108 Running a parametrized build with Copy Artifact's Build Selector breaks Ant functionality on Windows
-
- Resolved
-
[JENKINS-7442] Ant build steps with properties including variables are broken
This is, I'm fairly sure, the same problem as JENKINS-7657 - I've assigned that to mindless, who did a number of changes to Ant argument handling a while back. I believe that his changes are the underlying cause here.
Since JENKINS-7442 best describes my symptoms (more so than JENKINS-7657), this seems to have been introduced with .368. I can build under .367, however the same project(s) updated to 368 I receive the same error/condition of "inserted quotes" as explained in jwhackettuk's comments. thank you.
ant 1.7.1, jdk 1.6.0_18, running as service on win2003 server
Where is hudsonhome=%HUDSON_HOME% coming from?
Did you define a build parameter for this job called hudsonhome and enter %HUDSON_HOME% as its value? If so, that's not supported.. parameter values entered when starting a build are literal, so the quoting you see above is intentional escaping so ant receives the literal value %HUDSON_HOME%. If you want to access that value from ant, use a <property environment=..> tag to reference the environment..
HUDSON_HOME is set as environment variable outside Hudson on the operating system level.
Expansion of windows-style env var references is not supported in parameters.. Hudson internally uses only $ style references, so either use $HUDSON_HOME or remove the build parameter and use <property environment=..> in ant to reference environment variables (see ant documentation for <property>).
I re-open this.
Hudson itself is not involved in resolving Windows environment variables like %HUDSON_HOME%. This is done by cmd.exe. Hudson has to concatenate the command line with ant.bat correctly. Then windows can resolve the environment variables.
This worked with Hudson 1.365.
This is needed when I have foreign Ant scripts, which I cannot change. In this case I have to set properties for an Ant build step ('Advanced' Button).
Please see the above comment.. use $HUDSON_HOME if you want variable expansion in a property value. % chars in properties will be treated as literals and thus escaped.. can we reclose this? Or is there some situation where using $ will not work?
Using $HUDSON_HOME does not work. The call "cmd.exe /C ant.bat ..." then contains $HUDSON_HOME, which is not replaced by the value.
So we cannot re-close this issue.
Here is the Ant build step from the config.xml:
<hudson.tasks.Ant>
<targets>build_nightly</targets>
<antName>Ant 1.7.1</antName>
<buildFile>build.xml</buildFile>
<properties>build.number=%BUILD_NUMBER%
hudson.dir=%HUDSON_HOME%</properties>
</hudson.tasks.Ant>
Is this the detail you need?
This is also causing us headaches after an upgrade. $BUILD_NUMBER does not work. That only seems to work for build parameters, but not the meta variables Hudson sets (BUILD_NUMBER, JOB_NAME, etc.)
Can someone try this test on Windows?
Here is the build.xml to use:
<project name="foo" default="foo"> <target name="foo"> <echoproperties prefix="v"/> </target> </project>
And put this in the "properties" box of the Ant build step in your job:
vBNUM=$BUILD_NUMBER vBID=$BUILD_ID vBTAG=$BUILD_TAG vBURL=$BUILD_URL vEXEC=$EXECUTOR_NUMBER vHH=$HUDSON_HOME vHURL=$HUDSON_URL vJH=$JENKINS_HOME vJN=$JOB_NAME vJURL=$JOB_URL vNN=$NODE_NAME vNLAB=$NODE_LABELS vJAVH=$JAVA_HOME vWS=$WORKSPACE
Run the job and post the output here (obfuscate any paths, etc. as needed).. in my test (on mac, not windows) I found that $HUDSON_HOME and $BUILD_NUMBER worked OK, but a few did not..just the *_URL ones were missing.
Output from windows XP slave running 1.395 with ant 1.8.2
foo: [echoproperties] #Ant properties [echoproperties] #Tue Feb 15 18:31:05 GMT 2011 [echoproperties] vBID=2011-02-15_18-30-36 [echoproperties] vBNUM=5 [echoproperties] vBTAG=hudson-jenkins7442-5 [echoproperties] vBURL=http\://royalcounty/hudson/job/jenkins7442/5/ [echoproperties] vEXEC=0 [echoproperties] vHH=C\:\\richm\\hudson\\home [echoproperties] vHURL=http\://royalcounty/hudson/ [echoproperties] vJAVH=c\:\\richm\\hudson\\slave\\tools\\JDK_6 [echoproperties] vJH=$JENKINS_HOME [echoproperties] vJN=jenkins7442 [echoproperties] vJURL=http\://royalcounty/hudson/job/jenkins7442/ [echoproperties] vNLAB=Jive [echoproperties] vNN=Jive [echoproperties] vWS=c\:\\richm\\hudson\\slave\\workspace\\jenkins7442
mrobinet/skorsky: from the above output it looks like using $VAR form does work for all builtin vars.. can you try in your environment and see what behavior you get? Try upgrading to 1.395+ if needed.
Nice test case!
But it does not work with job names including blanks.
First the OK case with Jenkins-1.397:
[workspace] $ cmd.exe /C '"D:\Tools\apache-ant-1.8.2\bin\ant.bat -DvJURL=$JOB_URL -DvBTAG=$BUILD_TAG -DvNN=$NODE_NAME -DvBURL=$BUILD_URL -DvBID=$BUILD_ID -DvNLAB=$NODE_LABELS -DvHH=$HUDSON_HOME -DvJAVH=$JAVA_HOME -DvJN=$JOB_NAME -DvBNUM=$BUILD_NUMBER -DvHURL=$HUDSON_URL -DvWS=$WORKSPACE -DvJH=$JENKINS_HOME -DvEXEC=$EXECUTOR_NUMBER && exit %%ERRORLEVEL%%"'
Buildfile: D:\HudsonHome\jobs\Test-Jenkins7442\workspace\build.xml
foo:
[echoproperties] #Ant properties
[echoproperties] #Wed Feb 16 14:41:50 CET 2011
[echoproperties] vBID=2011-02-16_14-41-49
[echoproperties] vBNUM=4
[echoproperties] vBTAG=hudson-Test-Jenkins7442-4
[echoproperties] vBURL=http\://localhost\:8080/jenkins/job/Test-Jenkins7442/4/
[echoproperties] vEXEC=1
[echoproperties] vHH=D\:
HudsonHome
[echoproperties] vHURL=http\://localhost\:8080/jenkins/
[echoproperties] vJAVH=D\:\\Tools
jdk1.6.0_24
[echoproperties] vJH=D\:
HudsonHome
[echoproperties] vJN=Test-Jenkins7442
[echoproperties] vJURL=http\://localhost\:8080/jenkins/job/Test-Jenkins7442/
[echoproperties] vNLAB=master
[echoproperties] vNN=$NODE_NAME
[echoproperties] vWS=D\:\\HudsonHome\\jobs\\Test-Jenkins7442
workspace
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
Second the failure with Jenkins-1.397 and the job name ''.
[workspace] $ cmd.exe /C '"D:\Tools\apache-ant-1.8.2\bin\ant.bat -DvNN=$NODE_NAME -DvBID=$BUILD_ID -DvNLAB=$NODE_LABELS "-D""vJURL=$JOB_URL""" "-D""vBTAG=$BUILD_TAG""" -DvHH=$HUDSON_HOME -DvJAVH=$JAVA_HOME "-D""vJN=$JOB_NAME""" "-D""vBURL=$BUILD_URL""" -DvBNUM=$BUILD_NUMBER -DvHURL=$HUDSON_URL -DvJH=$JENKINS_HOME "-D""vWS=$WORKSPACE""" -DvEXEC=$EXECUTOR_NUMBER && exit %%ERRORLEVEL%%"'
Buildfile: D:\HudsonHome\jobs\Test Jenkins7442\workspace\build.xml
BUILD FAILED
Target "Jenkins7442-4"" does not exist in the project "foo".
Total time: 0 seconds
Finished: FAILURE
This worked with Hudson-1.365:
[workspace] $ cmd.exe /C '"\ant\apache-ant-1.8.1\bin\ant.bat -DvNN=$NODE_NAME -DvBID=$BUILD_ID -DvHOME=%HUDSON_HOME% -DvNLAB=$NODE_LABELS -D"vJURL=$JOB_URL" -D"vBTAG=$BUILD_TAG" -DvHH=$HUDSON_HOME -DvJAVH=$JAVA_HOME -D"vBURL=$BUILD_URL" -DvBNUM=$BUILD_NUMBER -DvHURL=$HUDSON_URL -D"vJN=$JOB_NAME" -DvJH=$JENKINS_HOME -D"vWS=$WORKSPACE" -DvEXEC=$EXECUTOR_NUMBER && exit %%ERRORLEVEL%%"'
Buildfile: C:\hudsonhome\jobs\Test Jenkins7442\workspace\build.xml
foo:
[echoproperties] #Ant properties
[echoproperties] #Wed Feb 16 15:09:25 CET 2011
[echoproperties] vBID=2011-02-16_15-09-24
[echoproperties] vBNUM=4
[echoproperties] vBTAG=hudson-Test Jenkins7442-4
[echoproperties] vBURL=http\://localhost\:8080/hudson/job/Test%20Jenkins7442/4/
[echoproperties] vEXEC=1
[echoproperties] vHH=C\:
hudsonhome
[echoproperties] vHOME=C\:
hudsonhome
[echoproperties] vHURL=http\://localhost\:8080/hudson/
[echoproperties] vJAVH=C\:
jdk1.6.0_21
[echoproperties] vJH=$JENKINS_HOME
[echoproperties] vJN=Test Jenkins7442
[echoproperties] vJURL=http\://localhost\:8080/hudson/job/Test%20Jenkins7442/
[echoproperties] vNLAB=$NODE_LABELS
[echoproperties] vNN=$NODE_NAME
[echoproperties] vWS=C\:\\hudsonhome\\jobs
Test Jenkins7442
workspace
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
The difference is
Hudson-1.365 builds the command line for ant with '-D"vJN=$JOB_NAME"'
while
Jenkins-1.397 builds the command line for ant with '"-D""vJN=$JOB_NAME"""'
The ant properties tab looks like:
vBNUM=$BUILD_NUMBER
vBID=$BUILD_ID
"vBTAG=$BUILD_TAG"
"vBURL=$BUILD_URL"
vEXEC=$EXECUTOR_NUMBER
vHH=$HUDSON_HOME
vHURL=$HUDSON_URL
vJH=$JENKINS_HOME
"vJN=$JOB_NAME"
"vJURL=$JOB_URL"
vNN=$NODE_NAME
vNLAB=$NODE_LABELS
vJAVH=$JAVA_HOME
"vWS=$WORKSPACE"
OK, I think the clue here is seeing $NODE_NAME, etc. in the command printed out in the log.. I believe they should already be expanded by then. Checking further..
Code changed in jenkins
User: alanharder
Path:
changelog.html
core/src/main/java/hudson/tasks/Ant.java
test/src/test/java/hudson/tasks/AntTest.java
http://jenkins-ci.org/commit/core/5f1fef602c6a5672df6edcc84c73c47ff70bb71b
Log:
[FIXED JENKINS-7442] Fix expansion of EnvVars in ant properties.
Ant build step had quite a mix: buildFile and antOpts expanded against
env, properties against buildVariables, and targets against both.
Now merging buildVariables into env and applying to all.
Please try this out in 1.399 (didn't make cut for 1.398 this week), thanks!
Integrated in jenkins_main_trunk #517
[FIXED JENKINS-7442] Fix expansion of EnvVars in ant properties.
alanharder :
Files :
- test/src/test/java/hudson/tasks/AntTest.java
- core/src/main/java/hudson/tasks/Ant.java
- changelog.html
When did the 1.399 being released , i've just switched from Hudson to Jenkins and this one break all the builds on my release server...
It should release a week from tomorrow. But you're welcome to try a dev build that already has this change:
http://ci.jenkins-ci.org/view/Jenkins%20core/job/jenkins_main_trunk/lastSuccessfulBuild/
Alan,
Jenkins ver. 1.399-SNAPSHOT (private-02/17/2011 01:03-slave)
Do the job when properties are used prefixed by a $ (as $BUILD_NUMBER) , there is always the same behaviour when using "normal" Win expansion in ant properties box ,in such a case , %BUILD_NUMBER% become "%B"UILD_NUMBER%" ...
By the way , if using $ should be the "Jenkins way" , it will be useful to add some lines about it on the wiki, or on the help box for the ant properties box .
There is still a problem with this..
if i need to use some env properties in the ant box , i still have to use %XXX% , and it is still badly escaped
Example
I have an env propertie SERVER_ROOT=c:\server
I want to set a ant properties with this value , so i put server.root=%SERVER_ROOT% in the ant properties box ..
At launch time this line is badly escaped as -Dserver.root="%S"ERVER_ROOT%" !!!!!!
Can you reOpen this issue ?
Reopening this. Still not fixed.
Using a job name with a blank does not work because variable expansion is broken.
Job name is 'Test Jenkins7442'.
Console output is:
[workspace] $ cmd.exe /C '"D:\Tools\apache-ant-1.8.2\bin\ant.bat -DvNN="" -DvBID=2011-03-04_18-27-43 -DvNLAB=master "-D""vJURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/""" "-D""vBTAG=jenkins-Test Jenkins7442-6""" -DvHH=D:\HudsonHome -DvJAVH=D:\Tools\jdk1.6.0_24 "-D""vBURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/6/""" -DvBNUM=6 -DvHURL=http://localhost:8080/jenkins/ "-D""vJN=Test Jenkins7442""" -DvJH=D:\HudsonHome "-D""vWS=D:\HudsonHome\jobs\Test Jenkins7442\workspace""" -DvEXEC=1 && exit %%ERRORLEVEL%%"'
Buildfile: D:\HudsonHome\jobs\Test Jenkins7442\workspace\build.xml
BUILD FAILED
Target "Jenkins7442-6"" does not exist in the project "foo".
Total time: 0 seconds
Finished: FAILURE
build.xml is:
<project name="foo" default="foo">
<target name="foo">
<echoproperties prefix="v"/>
</target>
</project>
Advanced build step properties are:
vBNUM=$BUILD_NUMBER
vBID=$BUILD_ID
"vBTAG=$BUILD_TAG"
"vBURL=$BUILD_URL"
vEXEC=$EXECUTOR_NUMBER
vHH=$HUDSON_HOME
vHURL=$HUDSON_URL
vJH=$JENKINS_HOME
"vJN=$JOB_NAME"
"vJURL=$JOB_URL"
vNN=$NODE_NAME
vNLAB=$NODE_LABELS
vJAVH=$JAVA_HOME
"vWS=$WORKSPACE"
I guess that $BUILD_TAG is broken and the second part of this is misused as an Ant target.
This is tested with Jenkins 1.399. Escaping the quotes has change, but is still not OK.
The expected command line on windows is for the example above:
"D:\Tools\apache-ant-1.8.2\bin\ant.bat -DvNN= -DvBID=2011-03-04_18-27-43 -DvNLAB=master "-DvJURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/" "-DvBTAG=jenkins-Test Jenkins7442-6" -DvHH=D:\HudsonHome -DvJAVH=D:\Tools\jdk1.6.0_24 "-DvBURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/6/" -DvBNUM=6 -DvHURL=http://localhost:8080/jenkins/ "-DvJN=Test Jenkins7442" -DvJH=D:\HudsonHome "-DvWS=D:\HudsonHome\jobs\Test Jenkins7442\workspace" -DvEXEC=1 && exit %%ERRORLEVEL%%"
Code changed in jenkins
User: alanharder
Path:
changelog.html
core/src/main/java/hudson/util/ArgumentListBuilder.java
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/jenkins/c4590529f731ba30b5deb0961d73f76e35ab70ff
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
I merged this into rc branch to go into tomorrow's 1.402 release.. let us know how it goes.
Code changed in jenkins
User: alanharder
Path:
changelog.html
core/src/main/java/hudson/util/ArgumentListBuilder.java
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/jenkins/3bd3ff9b572391606300f1ecfcad3eb62792d32d
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
Integrated in jenkins_main_trunk #602
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
alanharder : 3bd3ff9b572391606300f1ecfcad3eb62792d32d
Files :
- core/src/test/java/hudson/util/ArgumentListBuilderTest.java
- war/src/main/webapp/help/ant/ant-properties.html
- test/src/test/java/hudson/tasks/AntTest.java
- core/src/main/java/hudson/util/ArgumentListBuilder.java
- changelog.html
Sorry, but this is yet not fixed.
The command line for Ant on Windows expands "vBTAG=$BUILD_TAG"
to "-D""vBTAG=jenkins-Test Jenkins7442-6""". It should be "-DvBTAG=jenkins-Test Jenkins7442-6".
The windows cmd interprets the first as two arguments '-DvBTAG=jenkins-Test' and 'Jenkins7442-6"'. But this has to be one argument '-DvBTAG=jenkins-Test Jenkins7442-6'.
This happens regardless of using "vBTAG=$BUILD_TAG" or "vBTAG=%BUILD_TAG%".
Tested with Jenkins 1.403
sorry, not sure where your quotes are literal or not.
in the ant properties box did you enter:
vBTAG=$BUILD_TAG
or
"vBTAG=$BUILD_TAG"
?
Can you try the former and paste the line shown in the build console?
I used "vBTAG=$BUILD_TAG"
When I use vBTAG=$BUILD_TAG, it works fine. The command line is
[workspace] $ cmd.exe /C '"D:\Tools\apache-ant-1.8.2\bin\ant.bat -DvJURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/ "-DvBTAG=jenkins-Test Jenkins7442-4" -DvNN="" -DvBURL=http://localhost:8080/jenkins/job/Test%20Jenkins7442/4/ -DvBID=2011-03-22_17-52-13 -DvNLAB=master -DvHH=D:\HudsonHome -DvJAVH=D:\Tools\jdk1.6.0_24$ "-DvJN=Test Jenkins7442" -DvBNUM=4 -DvHURL=http://localhost:8080/jenkins/ "-DvWS=D:\HudsonHome\jobs\Test Jenkins7442\workspace" -DvJH=D:\HudsonHome -DvEXEC=1 && exit %%ERRORLEVEL%%"'
Ok, reclosing.
The help text already mentions issues with quotes, I believe.
Integrated in jenkins_main_trunk #620
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
alanharder : c4590529f731ba30b5deb0961d73f76e35ab70ff
Files :
- changelog.html
- war/src/main/webapp/help/ant/ant-properties.html
- test/src/test/java/hudson/tasks/AntTest.java
- core/src/test/java/hudson/util/ArgumentListBuilderTest.java
- core/src/main/java/hudson/util/ArgumentListBuilder.java
Code changed in jenkins
User: alanharder
Path:
core/src/main/java/hudson/tasks/Ant.java
test/src/test/java/hudson/tasks/AntTest.java
http://jenkins-ci.org/commit/ant-plugin/8971063149d1242188f25455a955cce4990e9eab
Log:
[FIXED JENKINS-7442] Fix expansion of EnvVars in ant properties.
Ant build step had quite a mix: buildFile and antOpts expanded against
env, properties against buildVariables, and targets against both.
Now merging buildVariables into env and applying to all.
Originally-Committed-As: 5f1fef602c6a5672df6edcc84c73c47ff70bb71b
Code changed in jenkins
User: alanharder
Path:
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/ant-plugin/f84ca39415be5312f9170de5a7ca4bf0278297fc
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
Originally-Committed-As: 3bd3ff9b572391606300f1ecfcad3eb62792d32d
Code changed in jenkins
User: alanharder
Path:
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/ant-plugin/e344ba82253b924a2ab3a321be265c400018946c
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
Originally-Committed-As: c4590529f731ba30b5deb0961d73f76e35ab70ff
Code changed in jenkins
User: alanharder
Path:
changelog.html
core/src/main/java/hudson/util/ArgumentListBuilder.java
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/jenkins/3bd3ff9b572391606300f1ecfcad3eb62792d32d
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
Code changed in jenkins
User: alanharder
Path:
changelog.html
core/src/main/java/hudson/util/ArgumentListBuilder.java
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
test/src/test/java/hudson/tasks/AntTest.java
war/src/main/webapp/help/ant/ant-properties.html
http://jenkins-ci.org/commit/jenkins/c4590529f731ba30b5deb0961d73f76e35ab70ff
Log:
[FIXED JENKINS-7442] Change ArgumentListBuilder.toWindowsCommand() to not escape %VAR%
type references by default (can now be done by passing "true" parameter).
This restores ability to use %VAR% references for ant build steps on windows.
I can confirm this. I've just updated from 376 and its broken %BUILD_ID% and %BUILD_NUMBER%
ant runs as
cmd.exe /C '"ant.bat -file build.xml "-DBUILD_ID=%"B"UILD_ID%" "-DBUILD_NUMBER=%"B"UILD_NUMBER%" release && exit %%ERRORLEVEL%%"'