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

Ant escape incorrectly on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: ant-plugin
    • Labels:
      None
    • Environment:
      Windows Server 2012, Windows 7
      Jenkins 1.634
      Ant plugin 1.2
      copyartifact plugin 1.36.1
      chrome browser, IE 11 browser
    • Similar Issues:

      Description

      Using BuildSelector to give a specific build number the CopyArtifact plugin step works fine.

      In a later step we run an ant script to deploy the artifacts in deploy job workspace now.

      The Ant generated parameter that appears to cause problem is "-DTARGET_BUILD=<SpecificBuildSelector plugin=""copyartifact@1.36.1""> <buildNumber>66</buildNumber></SpecificBuildSelector>"

      When runs gets error
      Target "<buildNumber>66</buildNumber></SpecificBuildSelector> -DBUILD_USER=xxxx" does not exist in the project

      This prevents running deploy job.

      The same deploy job running on Jenkins 1.476 and CopyArtifact plugin 1.29 and Ant 1.1 works.

      We are attempting to upgrade to a newer version of Jenkins and all the newer version use ant 1.2.

        Attachments

          Activity

          rberg Ruan Berg created issue -
          Hide
          ikedam ikedam added a comment -

          This looks an issue of ant-plugin (or might be that of Jenkins core?)
          Removed copyartifact from component/s.

          Show
          ikedam ikedam added a comment - This looks an issue of ant-plugin (or might be that of Jenkins core?) Removed copyartifact from component/s.
          ikedam ikedam made changes -
          Field Original Value New Value
          Component/s copyartifact-plugin [ 15692 ]
          Hide
          armfergom Armando Fernandez added a comment -

          Hi Ruan Berg,

          I recently took over manintainership of the Ant Plugin and got 1.3 released earlier this week. It should fix your issue. Please, could you confirm so that I can close this ticket?

          Thanks,
          Armando

          Show
          armfergom Armando Fernandez added a comment - Hi Ruan Berg , I recently took over manintainership of the Ant Plugin and got 1.3 released earlier this week. It should fix your issue. Please, could you confirm so that I can close this ticket? Thanks, Armando
          armfergom Armando Fernandez made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          armfergom Armando Fernandez made changes -
          Assignee Armando Fernandez [ armfergom ]
          Hide
          rberg Ruan Berg added a comment -

          it still fails after installing Ant Plugin 1.3

          [Batch.BatchControl.Deploy] $ cmd.exe /C "ant.bat -file AppDeploy.xml -DDEPLOY_ENV=IST '"-DTARGET_BUILD=<SpecificBuildSelector plugin=""copyartifact@1.38""> <buildNumber>65</buildNumber></SpecificBuildSelector>"' do_all -Djenkins.PREVJOBNAME=Batch.BatchControl -DSKIP_SERVICE_STEPS=true && exit %%ERRORLEVEL%%" Buildfile: ..\AppDeploy.xml [echo] Beginning Build of ..\AppDeployv5.xml with Ant Version Apache Ant(TM) version 1.9.6 compiled on June 29 2015... BUILD FAILED Target "<buildNumber>65</buildNumber></SpecificBuildSelector> do_all -Djenkins.PREVJOBNAME Batch.BatchControl -DSKIP_SERVICE_STEPS true" does not exist in the project "Web_Bld".

          Show
          rberg Ruan Berg added a comment - it still fails after installing Ant Plugin 1.3 [Batch.BatchControl.Deploy] $ cmd.exe /C "ant.bat -file AppDeploy.xml -DDEPLOY_ENV=IST '"-DTARGET_BUILD=<SpecificBuildSelector plugin=""copyartifact@1.38""> <buildNumber>65</buildNumber></SpecificBuildSelector>"' do_all -Djenkins.PREVJOBNAME=Batch.BatchControl -DSKIP_SERVICE_STEPS=true && exit %%ERRORLEVEL%%" Buildfile: ..\AppDeploy.xml [echo] Beginning Build of ..\AppDeployv5.xml with Ant Version Apache Ant(TM) version 1.9.6 compiled on June 29 2015... BUILD FAILED Target "<buildNumber>65</buildNumber></SpecificBuildSelector> do_all -Djenkins.PREVJOBNAME Batch.BatchControl -DSKIP_SERVICE_STEPS true" does not exist in the project "Web_Bld".
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 166286 ] JNJira + In-Review [ 185646 ]
          Hide
          thecycoone Stephen Baker added a comment - - edited

          I'm hitting this on 1.4 as well:

          ```
          [BoolParser] $ cmd.exe /C '""C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Ant_AntInstallation\Ant\bin\ant.bat"' -file build.xml -DGERRIT_BRANCH=develop -DGERRIT_PATCHSET_REVISION=65bed5205cb0ff069516de15ba02142bc1782e8a -DGERRIT_HOST=centos237.ermscorp.local -DGERRIT_CHANGE_OWNER_EMAIL=stephen.baker@example.com '"-DGERRIT_EVENT_ACCOUNT_NAME=Stephen Baker"' -DGERRIT_CHANGE_URL=http://centos237.ermscorp.local:8080/1242 -DGERRIT_PATCHSET_UPLOADER_EMAIL=stephen.baker@example.com -DGERRIT_EVENT_TYPE=patchset-created -DGERRIT_PROJECT=erms -DGERRIT_CHANGE_NUMBER=1242 -DGERRIT_SCHEME=ssh '"-DGERRIT_PATCHSET_UPLOADER=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_PORT=29418 -DGERRIT_REFSPEC=refs/changes/42/1242/2 '"-DGERRIT_PATCHSET_UPLOADER_NAME=Stephen Baker"' '"-DGERRIT_CHANGE_OWNER=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_CHANGE_COMMIT_MESSAGE=RmlsdGVyIHRoZSBtZW51IG9uIHRoZSBzZXJ2ZXIgc2lkZQoKQ2hhbmdlLUlkOiBJOTQ0OGFiM2RkMTUxYWVlMzhiODE0OTE5M2JlODNkZjBkMWViNDE3MQo="" '"-DGERRIT_NAME=Centos237 Gerrit Server"' -DGERRIT_TOPIC="" '"-DGERRIT_CHANGE_SUBJECT=Filter the menu on the server side"' '"-DGERRIT_EVENT_ACCOUNT=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_CHANGE_ID=I9448ab3dd151aee38b8149193be83df0d1eb4171 -DGERRIT_EVENT_HASH=-386756447 -DGERRIT_VERSION=2.11.5 -DGERRIT_EVENT_ACCOUNT_EMAIL=stephen.baker@example.com -DGERRIT_PATCHSET_NUMBER=2 '"-DGERRIT_CHANGE_OWNER_NAME=Stephen Baker"' jar && exit %%ERRORLEVEL%%"
          ```

          resulting in:
          ```
          Target "Baker"" <stephen.baker@example.com>" does not exist in the project "BoolParser".
          ```

          Show
          thecycoone Stephen Baker added a comment - - edited I'm hitting this on 1.4 as well: ``` [BoolParser] $ cmd.exe /C '""C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Ant_AntInstallation\Ant\bin\ant.bat"' -file build.xml -DGERRIT_BRANCH=develop -DGERRIT_PATCHSET_REVISION=65bed5205cb0ff069516de15ba02142bc1782e8a -DGERRIT_HOST=centos237.ermscorp.local -DGERRIT_CHANGE_OWNER_EMAIL=stephen.baker@example.com '"-DGERRIT_EVENT_ACCOUNT_NAME=Stephen Baker"' -DGERRIT_CHANGE_URL= http://centos237.ermscorp.local:8080/1242 -DGERRIT_PATCHSET_UPLOADER_EMAIL=stephen.baker@example.com -DGERRIT_EVENT_TYPE=patchset-created -DGERRIT_PROJECT=erms -DGERRIT_CHANGE_NUMBER=1242 -DGERRIT_SCHEME=ssh '"-DGERRIT_PATCHSET_UPLOADER=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_PORT=29418 -DGERRIT_REFSPEC=refs/changes/42/1242/2 '"-DGERRIT_PATCHSET_UPLOADER_NAME=Stephen Baker"' '"-DGERRIT_CHANGE_OWNER=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_CHANGE_COMMIT_MESSAGE=RmlsdGVyIHRoZSBtZW51IG9uIHRoZSBzZXJ2ZXIgc2lkZQoKQ2hhbmdlLUlkOiBJOTQ0OGFiM2RkMTUxYWVlMzhiODE0OTE5M2JlODNkZjBkMWViNDE3MQo="" '"-DGERRIT_NAME=Centos237 Gerrit Server"' -DGERRIT_TOPIC="" '"-DGERRIT_CHANGE_SUBJECT=Filter the menu on the server side"' '"-DGERRIT_EVENT_ACCOUNT=\""Stephen Baker\"" <stephen.baker@example.com>"' -DGERRIT_CHANGE_ID=I9448ab3dd151aee38b8149193be83df0d1eb4171 -DGERRIT_EVENT_HASH=-386756447 -DGERRIT_VERSION=2.11.5 -DGERRIT_EVENT_ACCOUNT_EMAIL=stephen.baker@example.com -DGERRIT_PATCHSET_NUMBER=2 '"-DGERRIT_CHANGE_OWNER_NAME=Stephen Baker"' jar && exit %%ERRORLEVEL%%" ``` resulting in: ``` Target "Baker"" <stephen.baker@example.com>" does not exist in the project "BoolParser". ```
          Hide
          sradi sradi added a comment -

          Hi there,

          I am facing the same issue with 1.4.
          Armando Fernandez: Can you provide a schedule, when the issue might be solved?

          If I can help with the fix, please contact me.
          I just don't have enough understanding of the code, and how to escape the command correctly, to start implementing a fix.

          Show
          sradi sradi added a comment - Hi there, I am facing the same issue with 1.4. Armando Fernandez : Can you provide a schedule, when the issue might be solved? If I can help with the fix, please contact me. I just don't have enough understanding of the code, and how to escape the command correctly, to start implementing a fix.
          Hide
          armfergom Armando Fernandez added a comment -

          sradi I'll try to get this done by the end of next week. Thanks and sorry for the delay.

          Show
          armfergom Armando Fernandez added a comment - sradi I'll try to get this done by the end of next week. Thanks and sorry for the delay.
          Hide
          sradi sradi added a comment -

          Thanks for the info!
          This issue seems to have the same cause, as JENKINS-37827.

          If it helps, here are the results of my little research:

          • I created a little job, that takes a string parameter and executes a simple ant build.
            Build parameter: string "with" double quotes
            On Jenkins 1.587 with ant plugin 1.2 I see this in the console output:
            cmd.exe /C '"ant.bat "-Denv=string ""with"" double quotes" foo && exit %%ERRORLEVEL%%"'
            ..works fine
            On Jenkins 2.32.1 with ant plugin 1.4 I see:
            cmd.exe /C "ant.bat '"-Denv=string ""with"" double quotes"' foo && exit %%ERRORLEVEL%%"
            ... works fine, as well.
          • Now I am adding backslashes, like e.g. the GitHub Pullrequest Builder Plugin does, in the environment variables injected into the job.
            Build parameter: string \"with\" double quotes
            On Jenkins 1.587 with ant plugin 1.2 I see this in the console output:
            cmd.exe /C '"ant.bat "-Denv=string \""with\"" double quotes" foo && exit %%ERRORLEVEL%%"'
            ..works fine
            On Jenkins 2.32.1 with ant plugin 1.4 I see:
            cmd.exe /C "ant.bat '"-Denv=string \""with\"" double quotes"' foo && exit %%ERRORLEVEL%%"
            ... works fine, as well.
          • Now I am adding a whitespace in between the double quotes:
            Build parameter: string \"with double\" quotes
            On Jenkins 1.587 with ant plugin 1.2 I see this in the console output:
            cmd.exe /C '"ant.bat "-Denv=string \""with double\"" quotes" foo && exit %%ERRORLEVEL%%"'
            ..BUILD FAILED: Target "double"" quotes" does not exist in the project "foo".
            On Jenkins 2.32.1 with ant plugin 1.4 I see:
            cmd.exe /C "ant.bat '"-Denv=string \""with double\"" quotes"' foo && exit %%ERRORLEVEL%%"
            ...BUILD FAILED: Target "double"" quotes" does not exist in the project "foo".

          Conclusion: The problem occurs, if there are whitespaces in between the double quotes,

          Show
          sradi sradi added a comment - Thanks for the info! This issue seems to have the same cause, as JENKINS-37827 . If it helps, here are the results of my little research: I created a little job, that takes a string parameter and executes a simple ant build. Build parameter : string "with" double quotes On Jenkins 1.587 with ant plugin 1.2 I see this in the console output: cmd.exe /C '"ant.bat "-Denv=string ""with"" double quotes" foo && exit %%ERRORLEVEL%%"' ..works fine On Jenkins 2.32.1 with ant plugin 1.4 I see: cmd.exe /C "ant.bat '"-Denv=string ""with"" double quotes"' foo && exit %%ERRORLEVEL%%" ... works fine, as well. Now I am adding backslashes, like e.g. the GitHub Pullrequest Builder Plugin does, in the environment variables injected into the job. Build parameter : string \"with\" double quotes On Jenkins 1.587 with ant plugin 1.2 I see this in the console output: cmd.exe /C '"ant.bat "-Denv=string \""with\"" double quotes" foo && exit %%ERRORLEVEL%%"' ..works fine On Jenkins 2.32.1 with ant plugin 1.4 I see: cmd.exe /C "ant.bat '"-Denv=string \""with\"" double quotes"' foo && exit %%ERRORLEVEL%%" ... works fine, as well. Now I am adding a whitespace in between the double quotes: Build parameter : string \"with double\" quotes On Jenkins 1.587 with ant plugin 1.2 I see this in the console output: cmd.exe /C '"ant.bat "-Denv=string \""with double\"" quotes" foo && exit %%ERRORLEVEL%%"' ..BUILD FAILED: Target "double"" quotes" does not exist in the project "foo". On Jenkins 2.32.1 with ant plugin 1.4 I see: cmd.exe /C "ant.bat '"-Denv=string \""with double\"" quotes"' foo && exit %%ERRORLEVEL%%" ...BUILD FAILED: Target "double"" quotes" does not exist in the project "foo". Conclusion: The problem occurs, if there are whitespaces in between the double quotes,
          Hide
          sradi sradi added a comment -

          Hi,

          we are urgently waiting for this bugfix. Is there any news about the timeline?
          If I can help, please contact me.

          Thanks!
          Stefan

          Show
          sradi sradi added a comment - Hi, we are urgently waiting for this bugfix. Is there any news about the timeline? If I can help, please contact me. Thanks! Stefan
          Hide
          sradi sradi added a comment -

          I am seeing this issue with the GitHub Pull Request Builder Plugin, not with Gerrit. The cause seems to be the same.

          Ghprb receives JSON from GitHub. The plugin provides information from this JSON object as Build parameters, e.g.

          "comment": {
          ...
           },
              "created_at": "2017-01-24T15:04:28Z",
              "updated_at": "2017-01-24T15:04:28Z",
              "body": "retrigger build\r\nwith \"line breaks and\" double quotes"
            },
          ...
          

          The Ghprb plugin escapes double quotes (""" -> "\""):
          https://github.com/janinko/ghprb/blob/master/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java#L366

          After modifying the line
          return text.replace("\n", "\\n").replace("\r", "\\r").replace("\"", "\\\"");
          to
          return text.replace("\n", "\\n").replace("\r", "
          r");

          everythings works fine!!!

          Maybe, this problem should be solved in Ghprb and Gerrit plugin, instead of the Ant plugin?!?
          How should the ant plugin be able to decide, if \" is an escaped double quote or a backslash and a double qoute?

          I could only test on windows. Probably the situation is different on unix.

          Show
          sradi sradi added a comment - I am seeing this issue with the GitHub Pull Request Builder Plugin, not with Gerrit. The cause seems to be the same. Ghprb receives JSON from GitHub. The plugin provides information from this JSON object as Build parameters, e.g. "comment" : { ... }, "created_at" : "2017-01-24T15:04:28Z" , "updated_at" : "2017-01-24T15:04:28Z" , "body" : "retrigger build\r\nwith \" line breaks and\ " double quotes" }, ... The Ghprb plugin escapes double quotes (""" -> "\""): https://github.com/janinko/ghprb/blob/master/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java#L366 After modifying the line return text.replace("\n", "\\n").replace("\r", "\\r").replace("\"", "\\\""); to return text.replace("\n", "\\n").replace("\r", " r"); everythings works fine!!! Maybe, this problem should be solved in Ghprb and Gerrit plugin, instead of the Ant plugin?!? How should the ant plugin be able to decide, if \" is an escaped double quote or a backslash and a double qoute? I could only test on windows. Probably the situation is different on unix.

            People

            Assignee:
            armfergom Armando Fernandez
            Reporter:
            rberg Ruan Berg
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: