You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JENKINS-7108] Running a parametrized build with Copy Artifact's Build Selector breaks Ant functionality on Windows #233
I have a Hudson job where the build needs to be parametrized. One of the required parameters for the build is the version of an artifact from another build. For this, I use "Build selector for Copy Artifact" as one of the user parameters for a build. The problem is that this causes an un-escaped xml tag to be passed in as an environment variable to an Ant build task.
For example, we have a Copy Artifact parameter by the name "build_selector". The ant target is "test". The ant build task then executes the following: cmd.exe /C '"ant.bat -file build.xml -Dbuild_selector= test && exit %%ERRORLEVEL%%"'. This results in an error message "The system cannot find the file specified.". This is occurring on my Hudson slave running Windows Server 2003 x64. Please let me know if I can provide any additional information in getting this issue resolved. Thank you.
I have a Hudson job where the build needs to be parametrized. One of the required parameters for the build is the version of an artifact from another build. For this, I use "Build selector for Copy Artifact" as one of the user parameters for a build. The problem is that this causes an un-escaped xml tag to be passed in as an environment variable to an Ant build task.
For example, we have a Copy Artifact parameter by the name "build_selector". The ant target is "test". The ant build task then executes the following: cmd.exe /C '"ant.bat -file build.xml -Dbuild_selector=<StatusBuildSelector/> test && exit %%ERRORLEVEL%%"'. This results in an error message "The system cannot find the file specified.". This is occurring on my Hudson slave running Windows Server 2003 x64. Please let me know if I can provide any additional information in getting this issue resolved. Thank you.
environment
Hudson Master running on Ubuntu Lucid<br/>
Hudson Slave running on Windows Server 2003 x64, controlled by Hudson Windows Slave Service
Can you do a test on your master node or other non-windows and see if that works for you? Can you also run a test on your windows slave where you use a simple String parameter instead of a build selector.. run a build and just put a value that has a < character and see if that also gets an error.
If you can confirm these, I'll dig deeper into how Hudson runs ant on windows..
Looks like the bug is in Hudson core, when running ant on windows. I tried this on Solaris, and it seems to work fine:
Can you do a test on your master node or other non-windows and see if that works for you? Can you also run a test on your windows slave where you use a simple String parameter instead of a build selector.. run a build and just put a value that has a < character and see if that also gets an error.
If you can confirm these, I'll dig deeper into how Hudson runs ant on windows..
I think you are right mindless. I ran some tests on both my Windows 2003 Builder as well as my Ubuntu Hudson master. Ubuntu handles the property variables well, but Windows does not. Here are some sample runs with a simple string parameter in hudson:
==WINDOWS 2003==
#With no param variables
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar=hello
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar=<hello
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=<hello test && exit %%ERRORLEVEL%%"'
The system cannot find the file specified.
Finished: FAILURE
#In the case of "hello>" the target is lost, and the output is piped to a file called test instead of launching the target test.
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello> test && exit %%ERRORLEVEL%%"'
Finished: SUCCESS
==UBUNTU LUCID==
Started by user anonymous
Building on master
[pranava] $ ant -file build.xml -Dtestvar=<hello test
Buildfile: /home/tester/build.xml
test:
[echo] hello world
[echo] <hello
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
Started by user anonymous
Building on master
[pranava] $ ant -file build.xml -Dtestvar=hello> test
Buildfile: /home/tester/build.xml
test:
[echo] hello world
[echo] hello>
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
I think you are right mindless. I ran some tests on both my Windows 2003 Builder as well as my Ubuntu Hudson master. Ubuntu handles the property variables well, but Windows does not. Here are some sample runs with a simple string parameter in hudson:
==WINDOWS 2003==
#With no param variables
Started by user anonymous
Building remotely on hudson_slave_builder [pranava] $ cmd.exe /C '"ant.bat -file build.xml test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test: [echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar=hello
Started by user anonymous
Building remotely on hudson_slave_builder [pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test: [echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar=
Started by user anonymous
Building remotely on hudson_slave_builder [pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=
The system cannot find the file specified.
Finished: FAILURE
#In the case of "hello>" the target is lost, and the output is piped to a file called test instead of launching the target test.
Started by user anonymous
Building remotely on hudson_slave_builder [pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello> test && exit %%ERRORLEVEL%%"'
Finished: SUCCESS
==UBUNTU LUCID==
Started by user anonymous
Building on master [pranava] $ ant -file build.xml -Dtestvar=
Buildfile: /home/tester/build.xml
test: [echo] hello world [echo]
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
Started by user anonymous
Building on master [pranava] $ ant -file build.xml -Dtestvar=hello> test
Buildfile: /home/tester/build.xml
test: [echo] hello world [echo] hello>
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
Code changed in hudson
User: : mindless
Path:
trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java
trunk/hudson/main/core/src/test/java/hudson/util/ArgumentListBuilderTest.java
http://jenkins-ci.org/commit/33530
Log:
JENKINS-7108 add ArgumentListBuilder.toWindowsCommand() which wraps command
in CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
Code changed in hudson
User: : mindless
Path:
trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java
trunk/hudson/main/core/src/test/java/hudson/util/ArgumentListBuilderTest.java http://jenkins-ci.org/commit/33530
Log: JENKINS-7108">JENKINS-7108 add ArgumentListBuilder.toWindowsCommand() which wraps command
in CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
Integrated in hudson_main_trunk #153JENKINS-7108 add ArgumentListBuilder.toWindowsCommand() which wraps command
in CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
Integrated in hudson_main_trunk #153 JENKINS-7108">JENKINS-7108 add ArgumentListBuilder.toWindowsCommand() which wraps command
in CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
Hello mindless, the escaping issue seems to be taken care of on my Windows machine. I ran a test job with a parameter test_param. Here is the output:
Started by user anonymous
[ant_files] $ cmd.exe /C '"ant.bat -file build.xml "-Dtest_param=test^<to see if redirecting is ^>escaped" test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello, world
[echo] test^<to see if redirecting is ^>escaped
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
It looks good, except do you know why these carets are showing up? Thanks!
Hello mindless, the escaping issue seems to be taken care of on my Windows machine. I ran a test job with a parameter test_param. Here is the output:
Started by user anonymous [ant_files] $ cmd.exe /C '"ant.bat -file build.xml "-Dtest_param=test^escaped" test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test: [echo] hello, world [echo] test^escaped
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
It looks good, except do you know why these carets are showing up? Thanks!
Hm.. the ^ chars are expected.. in my testing, without ^ for escaping, the < was still interpreted as redirection, even when the param has " " around it. I tested on Windows XP.
What windows version are you using?
Can you try the above cmd.exe ..... command from a command prompt? What happens with/without the ^ char?
Hm.. the ^ chars are expected.. in my testing, without ^ for escaping, the < was still interpreted as redirection, even when the param has " " around it. I tested on Windows XP.
What windows version are you using?
Can you try the above cmd.exe ..... command from a command prompt? What happens with/without the ^ char?
I see your windows version in the "environment" above.. so, please test from command prompt to see if something is different when running in Hudson, or behavior is actually different for different windows versions..
I see your windows version in the "environment" above.. so, please test from command prompt to see if something is different when running in Hudson, or behavior is actually different for different windows versions..
Activity
jenkins-infra-bot commentedon Jul 30, 2010
Raw content of original comment:
Looks like the bug is in Hudson core, when running ant on windows. I tried this on Solaris, and it seems to work fine:
Can you do a test on your master node or other non-windows and see if that works for you? Can you also run a test on your windows slave where you use a simple String parameter instead of a build selector.. run a build and just put a value that has a < character and see if that also gets an error.
If you can confirm these, I'll dig deeper into how Hudson runs ant on windows..
jenkins-infra-bot commentedon Jul 30, 2010
thenava:
Raw content of original comment:
I think you are right mindless. I ran some tests on both my Windows 2003 Builder as well as my Ubuntu Hudson master. Ubuntu handles the property variables well, but Windows does not. Here are some sample runs with a simple string parameter in hudson:
==WINDOWS 2003==
#With no param variables
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar=hello
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello world
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
#With a param variable testvar= Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar= The system cannot find the file specified.
Finished: FAILURE
#In the case of "hello>" the target is lost, and the output is piped to a file called test instead of launching the target test.
Started by user anonymous
Building remotely on hudson_slave_builder
[pranava] $ cmd.exe /C '"ant.bat -file build.xml -Dtestvar=hello> test && exit %%ERRORLEVEL%%"'
Finished: SUCCESS
==UBUNTU LUCID==
Started by user anonymous
Building on master
[pranava] $ ant -file build.xml -Dtestvar= Buildfile: /home/tester/build.xml
test:
[echo] hello world
[echo]
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
Started by user anonymous
Building on master
[pranava] $ ant -file build.xml -Dtestvar=hello> test
Buildfile: /home/tester/build.xml
test:
[echo] hello world
[echo] hello>
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
jenkins-infra-bot commentedon Aug 2, 2010
Raw content of original comment:
Code changed in hudson
User: : mindless
Path:
trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java
trunk/hudson/main/core/src/test/java/hudson/util/ArgumentListBuilderTest.java
http://jenkins-ci.org/commit/33530
Log:
JENKINS-7108">
JENKINS-7108add ArgumentListBuilder.toWindowsCommand() which wraps commandin CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
jenkins-infra-bot commentedon Aug 2, 2010
Raw content of original comment:
Integrated in
hudson_main_trunk #153
JENKINS-7108">
JENKINS-7108add ArgumentListBuilder.toWindowsCommand() which wraps commandin CMD.EXE /C (as Ant.perform() already did), but also does escaping of special
characters to ensure argument as passed unaltered. Use this in Ant.perform() so
build parameters with < or > characters don't cause I/O redirection, for example.
mindless :
Files :
jenkins-infra-bot commentedon Aug 2, 2010
Raw content of original comment:
thenava, can you do some testing on the latest dev build ? I'd like to get some verification before marking this as fixed.. thanks.
jenkins-infra-bot commentedon Aug 5, 2010
thenava:
Raw content of original comment:
Hello mindless, the escaping issue seems to be taken care of on my Windows machine. I ran a test job with a parameter test_param. Here is the output:
Started by user anonymous
[ant_files] $ cmd.exe /C '"ant.bat -file build.xml "-Dtest_param=test^escaped" test && exit %%ERRORLEVEL%%"'
Buildfile: build.xml
test:
[echo] hello, world
[echo] test^escaped
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
It looks good, except do you know why these carets are showing up? Thanks!
jenkins-infra-bot commentedon Aug 18, 2010
Raw content of original comment:
Hm.. the ^ chars are expected.. in my testing, without ^ for escaping, the < was still interpreted as redirection, even when the param has " " around it. I tested on Windows XP.
What windows version are you using?
Can you try the above cmd.exe ..... command from a command prompt? What happens with/without the ^ char?
jenkins-infra-bot commentedon Aug 18, 2010
Raw content of original comment:
I see your windows version in the "environment" above.. so, please test from command prompt to see if something is different when running in Hudson, or behavior is actually different for different windows versions..
jenkins-infra-bot commentedon Aug 27, 2010
Raw content of original comment:
thenava (or anyone), any updates?
jenkins-infra-bot commentedon Aug 31, 2010
Raw content of original comment:
I'm marking this as fixed.. if anyone sees new problems due to this escaping for ant on windows, please open a new issue. thanks.
jenkins-infra-bot commentedon Dec 16, 2025
[Original
relates_tofrom Jira: JENKINS-7442]jenkins-infra-bot commentedon Dec 16, 2025
[Original
relates_tofrom Jira: JENKINS-7657]jenkins-infra-bot commentedon Dec 16, 2025
[Original
relates_tofrom Jira: JENKINS-7204]