Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-7108

Running a parametrized build with Copy Artifact's Build Selector breaks Ant functionality on Windows

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • ant-plugin
    • None
    • Hudson Master running on Ubuntu Lucid
      Hudson Slave running on Windows Server 2003 x64, controlled by Hudson Windows Slave Service

      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.

          [JENKINS-7108] Running a parametrized build with Copy Artifact's Build Selector breaks Ant functionality on Windows

          Alan Harder added a comment - - edited

          Looks like the bug is in Hudson core, when running ant on windows. I tried this on Solaris, and it seems to work fine:

          [workspace] $ /path/to/apache-ant-1.7.1/bin/ant "-DBUILD_SELECTOR=<StatusBuildSelector>
            <stable>true</stable>
          </StatusBuildSelector>"
          Buildfile: build.xml
          
          foo:
          [echoproperties] #Ant properties
          [echoproperties] #Fri Jul 30 16:10:19 MDT 2010
          [echoproperties] BUILD_SELECTOR=<StatusBuildSelector> <stable>true</stable> </StatusBuildSelector>
          ...
          

          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..

          Alan Harder added a comment - - edited Looks like the bug is in Hudson core, when running ant on windows. I tried this on Solaris, and it seems to work fine: [workspace] $ /path/to/apache-ant-1.7.1/bin/ant "-DBUILD_SELECTOR=<StatusBuildSelector> <stable>true</stable> </StatusBuildSelector>" Buildfile: build.xml foo: [echoproperties] #Ant properties [echoproperties] #Fri Jul 30 16:10:19 MDT 2010 [echoproperties] BUILD_SELECTOR=<StatusBuildSelector> <stable>true</stable> </StatusBuildSelector> ... 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..

          thenava added a comment - - edited

          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

          thenava added a comment - - edited 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

          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.

          SCM/JIRA link daemon added a 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 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.

          dogfood added a comment -

          Integrated in hudson_main_trunk #153
          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.

          mindless :
          Files :

          • /trunk/hudson/main/core/src/test/java/hudson/util/ArgumentListBuilderTest.java
          • /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
          • /trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java

          dogfood added a comment - Integrated in hudson_main_trunk #153 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. mindless : Files : /trunk/hudson/main/core/src/test/java/hudson/util/ArgumentListBuilderTest.java /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java /trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java

          Alan Harder added a 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.

          Alan Harder added a 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.

          thenava added a 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^<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!

          thenava added a 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^<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!

          Alan Harder added a 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?

          Alan Harder added a 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?

          Alan Harder added a 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..

          Alan Harder added a 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..

          Alan Harder added a comment -

          thenava (or anyone), any updates?

          Alan Harder added a comment - thenava (or anyone), any updates?

          Alan Harder added a 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.

          Alan Harder added a 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.

            mindless Alan Harder
            thenava thenava
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: