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

Ant properties are quoted incorrectly on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Environment:
      Hudson 1.371
      Ant 1.7.1
    • Similar Issues:

      Description

      The latest Hudson seems to quote Ant properties incorrectly. Older versions of Hudson did not have the same problem. The quote problem makes it impossible to define an empty Ant property.

      Steps to reproduce:

      1. Create new free style job
      2. Run the job to create a workspace folder
      3. Add the following file to the job workspace:
        build.xml
        <project default="build" basedir=".">
            <target name="build">
                <echo message="Value: '${value}'" />
            </target>
        </project>
        
      4. Reconfigure the hudson job to invoke Ant
      5. In the Ant properties field write:
        value=""
        
      6. Run the job

      Excepted result:
      The Ant script should show that the value property was blank

      Actual result:
      The Ant script show that the value property is actual "".

      Additional information:
      In the console output of the job Hudson 1.371 displays:
      [workspace] $ cmd.exe /C '"ant.bat "-Dvalue=""""" && exit %%ERRORLEVEL%%"'

      In the console output of the job in older Hudson's (1.361 and earlier) displayed:
      [workspace] $ cmd.exe /C '"ant.bat -Dvalue="" build && exit %%ERRORLEVEL%%"'

        Attachments

          Issue Links

            Activity

            amh Anders Hansen created issue -
            mindless Alan Harder made changes -
            Field Original Value New Value
            Assignee huybrechts [ huybrechts ]
            Summary Ant properties are quoted incorrectly Ant properties are quoted incorrectly on Windows
            mindless Alan Harder made changes -
            Link This issue is related to JENKINS-7108 [ JENKINS-7108 ]
            Hide
            amh Anders Hansen added a comment -

            Updated the issue formatting to make it easier to read.
            Corrected minor textual errors.

            Show
            amh Anders Hansen added a comment - Updated the issue formatting to make it easier to read. Corrected minor textual errors.
            amh Anders Hansen made changes -
            Description The latest Hudson seems to quote Ant properties incorrectly. Older versions of Hudson did not have the same problems. The quote problem makes it impossible to define an empty Ant property.

            Steps to reproduce:
            1)Create new free style job
            2)Run the job to create a workspace folder
            3)Add the following file to the job workspace:
            build.xml:
            <project default="build" basedir=".">
            <target name="build">
            <echo message="Value: '${value}'" />
            </target>
            </project>

            4)Reconfigure the hudson job to invoke Ant
            5)In the Ant properties field write:
            value=""
            6)Run the job

            Excepted result:
            The Ant script should show that the value property was blank

            Actual result:
            The Ant script show that the value property is actual "".

            Additional information:
            In the console output of the job Hudson 1.371 displays:
            [workspace] $ cmd.exe /C '"c:\apache-ant-1.7.1\bin\ant.bat "-Dvalue=""""" && exit %%ERRORLEVEL%%"'

            In the console output of the job in older Hudson's (1.361 and earlier) displaed:
            [workspace] $ cmd.exe /C '"ant.bat -Dvalue="" build && exit %%ERRORLEVEL%%"'
            The latest Hudson seems to quote Ant properties incorrectly. Older versions of Hudson did not have the same problem. The quote problem makes it impossible to define an empty Ant property.

            Steps to reproduce:
            # Create new free style job
            # Run the job to create a workspace folder
            # Add the following file to the job workspace:
            {code:title=build.xml}
            <project default="build" basedir=".">
                <target name="build">
                    <echo message="Value: '${value}'" />
                </target>
            </project>
            {code}
            # Reconfigure the hudson job to invoke Ant
            # In the Ant properties field write:
            {code:xml}
            value=""
            {code}
            # Run the job
            \\ \\

            Excepted result:
            The Ant script should show that the value property was blank

            Actual result:
            The Ant script show that the value property is actual "".

            Additional information:
            In the console output of the job Hudson 1.371 displays:
            [workspace] $ cmd.exe /C '"ant.bat "-Dvalue=""""" && exit %%ERRORLEVEL%%"'

            In the console output of the job in older Hudson's (1.361 and earlier) displayed:
            [workspace] $ cmd.exe /C '"ant.bat -Dvalue="" build && exit %%ERRORLEVEL%%"'
            Hide
            mindless Alan Harder added a comment -

            The escaping that was added was indended to apply to build parameters (values here expected to be literal), NOT properties entered directly into the ant build step (variable expansion supported here).. will need to dig into how to handle these separately.

            Show
            mindless Alan Harder added a comment - The escaping that was added was indended to apply to build parameters (values here expected to be literal), NOT properties entered directly into the ant build step (variable expansion supported here).. will need to dig into how to handle these separately.
            Hide
            mindless Alan Harder added a comment -

            out of curiosity, what if you enter just
            value=
            in the properties? Does that work for empty value?

            Show
            mindless Alan Harder added a comment - out of curiosity, what if you enter just value= in the properties? Does that work for empty value?
            Hide
            mindless Alan Harder added a comment -

            I found that the person reporting a similar problem on the alias was using %VAR% form instead of $VAR.. even running ant build on windows you should use $VAR form in the ant properties box, as Hudson will expand that before any escaping is done.
            So, if just
            value=
            works for the case you're reporting here, then I'm inclined to close this issue. Let me know how it goes, and if you know of any other cases that don't work with the new escaping stuff. Thanks.

            Show
            mindless Alan Harder added a comment - I found that the person reporting a similar problem on the alias was using %VAR% form instead of $VAR.. even running ant build on windows you should use $VAR form in the ant properties box, as Hudson will expand that before any escaping is done. So, if just value= works for the case you're reporting here, then I'm inclined to close this issue. Let me know how it goes, and if you know of any other cases that don't work with the new escaping stuff. Thanks.
            Hide
            amh Anders Hansen added a comment -

            Defining a property without a value makes the Hudson build fail. If the test is run directly against Ant from a command prompt Ant reports: "Missing value for property value".

            Steps:
            1) Change the Ant properties to:

            value=
            

            Hudson console output:

            Started by user anonymous
            Building on master
            [workspace] $ cmd.exe /C '"ant.bat -Dvalue= && exit %%ERRORLEVEL%%"'
            Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
            Missing value for property value
            Finished: FAILURE
            

            Single quotes seems to escaped correctly in Hudson. Ant reports the same value in Hudson as when the the script is run from a command prompt.

            Hudson console output on single quotes:

            Started by user anonymous
            Building on master
            [workspace] $ cmd.exe /C '"ant.bat -Dvalue='' && exit %%ERRORLEVEL%%"'
            Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
            Buildfile: build.xml
            
            build:
                 [echo] Value: ''''
            
            BUILD SUCCESSFUL
            Total time: 0 seconds
            Finished: SUCCESS
            
            Show
            amh Anders Hansen added a comment - Defining a property without a value makes the Hudson build fail. If the test is run directly against Ant from a command prompt Ant reports: "Missing value for property value". Steps: 1) Change the Ant properties to: value= Hudson console output: Started by user anonymous Building on master [workspace] $ cmd.exe /C ' "ant.bat -Dvalue= && exit %%ERRORLEVEL%%" ' Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar Missing value for property value Finished: FAILURE Single quotes seems to escaped correctly in Hudson. Ant reports the same value in Hudson as when the the script is run from a command prompt. Hudson console output on single quotes: Started by user anonymous Building on master [workspace] $ cmd.exe /C ' "ant.bat -Dvalue=' ' && exit %%ERRORLEVEL%%" ' Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar Buildfile: build.xml build: [echo] Value: '''' BUILD SUCCESSFUL Total time: 0 seconds Finished: SUCCESS
            Hide
            mindless Alan Harder added a comment -

            yes, I see that too.. that's odd.
            "ant -Dfoo= mytest" works fine on unix..
            I'll see what I can do..

            Show
            mindless Alan Harder added a comment - yes, I see that too.. that's odd. "ant -Dfoo= mytest" works fine on unix.. I'll see what I can do..
            mindless Alan Harder made changes -
            Assignee mindless [ mindless ]
            Hide
            scm_issue_link 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/war/resources/help/ant/ant-properties.html
            http://jenkins-ci.org/commit/33988
            Log:
            JENKINS-7204 fix for defining empty properties for ant build on windows.
            also added info about parameter references and double quotes in help file.

            Show
            scm_issue_link 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/war/resources/help/ant/ant-properties.html http://jenkins-ci.org/commit/33988 Log: JENKINS-7204 fix for defining empty properties for ant build on windows. also added info about parameter references and double quotes in help file.
            Hide
            mindless Alan Harder added a comment -

            Please test with http://ci.hudson-labs.org/job/hudson_main_trunk/lastSuccessfulBuild/artifact/main/war/target/hudson.war and let me know if it works.. you should use
            name=
            instead of
            name=""

            Show
            mindless Alan Harder added a comment - Please test with http://ci.hudson-labs.org/job/hudson_main_trunk/lastSuccessfulBuild/artifact/main/war/target/hudson.war and let me know if it works.. you should use name= instead of name=""
            Hide
            dogfood dogfood added a comment -

            Integrated in hudson_main_trunk #196
            JENKINS-7204 fix for defining empty properties for ant build on windows.
            also added info about parameter references and double quotes in help file.

            mindless :
            Files :

            • /trunk/hudson/main/war/resources/help/ant/ant-properties.html
            • /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
            • /trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java
            Show
            dogfood dogfood added a comment - Integrated in hudson_main_trunk #196 JENKINS-7204 fix for defining empty properties for ant build on windows. also added info about parameter references and double quotes in help file. mindless : Files : /trunk/hudson/main/war/resources/help/ant/ant-properties.html /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java /trunk/hudson/main/core/src/main/java/hudson/util/ArgumentListBuilder.java
            Hide
            amh Anders Hansen added a comment -

            Tested the hudson_main_trunk #196 build. It works perfectly.

            Setting value to:

            value=""
            

            Gives the output:

            [workspace] $ cmd.exe /C '"ant.bat "-Dvalue=""""" && exit %%ERRORLEVEL%%"'
            Buildfile: build.xml
            
            build:
                 [echo] Value: '""'
            BUILD SUCCESSFUL
            

            Setting value to:

            value=
            

            Gives the output:

            [workspace] $ cmd.exe /C '"ant.bat -Dvalue="" && exit %%ERRORLEVEL%%"'
            Buildfile: build.xml
            
            build:
                 [echo] Value: ''
            
            BUILD SUCCESSFUL
            

            Setting value to:

            value=''
            

            Gives the output:

            [workspace] $ cmd.exe /C '"ant.bat -Dvalue='' && exit %%ERRORLEVEL%%"'
            Buildfile: build.xml
            
            build:
                 [echo] Value: ''''
            
            BUILD SUCCESSFUL
            
            Show
            amh Anders Hansen added a comment - Tested the hudson_main_trunk #196 build. It works perfectly. Setting value to: value="" Gives the output: [workspace] $ cmd.exe /C ' "ant.bat " -Dvalue= """"" && exit %%ERRORLEVEL%%" ' Buildfile: build.xml build: [echo] Value: '""' BUILD SUCCESSFUL Setting value to: value= Gives the output: [workspace] $ cmd.exe /C ' "ant.bat -Dvalue=" " && exit %%ERRORLEVEL%%" ' Buildfile: build.xml build: [echo] Value: '' BUILD SUCCESSFUL Setting value to: value='' Gives the output: [workspace] $ cmd.exe /C ' "ant.bat -Dvalue=' ' && exit %%ERRORLEVEL%%" ' Buildfile: build.xml build: [echo] Value: '''' BUILD SUCCESSFUL
            abayer Andrew Bayer made changes -
            Link This issue is duplicated by JENKINS-5157 [ JENKINS-5157 ]
            amh Anders Hansen made changes -
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            Hide
            macosgrove macosgrove added a comment - - edited

            This is not quite working for all parameters. I am using parameters in the job configuration, set as follows:

            [Choice] environment=sys-test
            [String] releaseTag=September_2010.9708
            [String] dbVersion=September_2010
            [String] dbOrigin=
            [String] comments=
            [String] datetime=
            [Choice] tester=

            This results in $ cmd.exe /C '"ant.bat -file build-trac.xml -Dtester="" -DdbOrigin= -DreleaseTag=September_2010.9708 -Denvironment=sys-test -Ddatetime="" -Dcomments= -DdbVersion=September_2010 -DdeployEnvironment=ci updateDeploymentHistory -verbose && exit %%ERRORLEVEL%%"'

            which fails because of the lack of quotes on dbOrigin and comments. I don't understand why these are treated differently from datetime, which is quoted correctly and works.

            I am using Windows XP SP3 for client and server, Hudson 1.374

            Show
            macosgrove macosgrove added a comment - - edited This is not quite working for all parameters. I am using parameters in the job configuration, set as follows: [Choice] environment=sys-test [String] releaseTag=September_2010.9708 [String] dbVersion=September_2010 [String] dbOrigin= [String] comments= [String] datetime= [Choice] tester= This results in $ cmd.exe /C '"ant.bat -file build-trac.xml -Dtester="" -DdbOrigin= -DreleaseTag=September_2010.9708 -Denvironment=sys-test -Ddatetime="" -Dcomments= -DdbVersion=September_2010 -DdeployEnvironment=ci updateDeploymentHistory -verbose && exit %%ERRORLEVEL%%"' which fails because of the lack of quotes on dbOrigin and comments. I don't understand why these are treated differently from datetime, which is quoted correctly and works. I am using Windows XP SP3 for client and server, Hudson 1.374
            macosgrove macosgrove made changes -
            Resolution Fixed [ 1 ]
            Status Closed [ 6 ] Reopened [ 4 ]
            Hide
            kirill_evstigneev Kirill Evstigneev added a comment -

            Another problem with Ant command line quoting - comma in a property value:
            name=foo,bar

            Show
            kirill_evstigneev Kirill Evstigneev added a comment - Another problem with Ant command line quoting - comma in a property value: name=foo,bar
            kirill_evstigneev Kirill Evstigneev made changes -
            Link This issue is related to JENKINS-2149 [ JENKINS-2149 ]
            Hide
            scm_issue_link 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/www/changelog.html
            http://jenkins-ci.org/commit/34228
            Log:
            JENKINS-7204 update regexp to work for 2 consecutive empty properties

            Show
            scm_issue_link 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/www/changelog.html http://jenkins-ci.org/commit/34228 Log: JENKINS-7204 update regexp to work for 2 consecutive empty properties
            mindless Alan Harder made changes -
            Resolution Fixed [ 1 ]
            Status Reopened [ 4 ] Resolved [ 5 ]
            Hide
            dogfood dogfood added a comment -

            Integrated in hudson_main_trunk #234
            JENKINS-7204 update regexp to work for 2 consecutive empty properties

            mindless :
            Files :

            • /trunk/www/changelog.html
            • /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
            Show
            dogfood dogfood added a comment - Integrated in hudson_main_trunk #234 JENKINS-7204 update regexp to work for 2 consecutive empty properties mindless : Files : /trunk/www/changelog.html /trunk/hudson/main/core/src/main/java/hudson/tasks/Ant.java
            amh Anders Hansen made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            ircbot Jenkins IRC Bot made changes -
            Component/s core [ 15593 ]
            Component/s parameters [ 15594 ]
            benapgar Ben Apgar made changes -
            Link This issue is related to JENKINS-33712 [ JENKINS-33712 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 137303 ] JNJira + In-Review [ 204456 ]

              People

              Assignee:
              mindless Alan Harder
              Reporter:
              amh Anders Hansen
              Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: