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

Ant escape incorrectly on Windows

    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

          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: