Skip to content

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

Closed

Description

@jenkins-infra-bot

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.


Originally reported by thenava, imported from: Running a parametrized build with Copy Artifact's Build Selector breaks Ant functionality on Windows
  • assignee: mindless
  • status: Resolved
  • priority: Critical
  • component(s): ant-plugin
  • resolution: Fixed
  • resolved: 2010-08-31T08:51:57+00:00
  • votes: 0
  • watchers: 1
  • imported: 20251216-182730
Raw content of original issue

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

Activity

  1. jenkins-infra-bot commented on Jul 30, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • 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:

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

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

  2. jenkins-infra-bot commented on Jul 30, 2010

    @jenkins-infra-bot
    Author
    thenava:
    • Original comment link
    • 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=<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

  3. jenkins-infra-bot commented on Aug 2, 2010

    @jenkins-infra-bot
    Author
    scm_issue_link:
    • Original comment link
    • 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 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.

  4. jenkins-infra-bot commented on Aug 2, 2010

    @jenkins-infra-bot
    Author
    dogfood:
    • Original comment link
    • Raw content of original 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

    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.

    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
  5. jenkins-infra-bot commented on Aug 2, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • 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.

    thenava, can you do some testing on the latest dev build ? I'd like to get some verification before marking this as fixed.. thanks.

  6. jenkins-infra-bot commented on Aug 5, 2010

    @jenkins-infra-bot
    Author
    thenava:
    • Original comment link
    • 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^<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!

  7. jenkins-infra-bot commented on Aug 18, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • 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?

    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?

  8. jenkins-infra-bot commented on Aug 18, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • 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..

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

  9. jenkins-infra-bot commented on Aug 27, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • Raw content of original comment:

      thenava (or anyone), any updates?

    thenava (or anyone), any updates?

  10. jenkins-infra-bot commented on Aug 31, 2010

    @jenkins-infra-bot
    Author
    mindless:
    • Original comment link
    • 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.

    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.

  11. jenkins-infra-bot commented on Dec 16, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-7442]

  12. jenkins-infra-bot commented on Dec 16, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-7657]

  13. jenkins-infra-bot commented on Dec 16, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-7204]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions