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

Gerrit-plugin modifies ant command line which is not compatible on windows

      Gerrit modified my ant task by adding GIT specific environment variables in a way that causes the ant task to go belly up.

      Here is a snippet from the log from a build where I have turned the escaping off. Note that the escaping option doesn't really fix the problem. Both variants (escaping on and off) fail.

      16:18:18  c:\temp\hudsonwork\gerrit>exit 0 
      16:18:18  [TestProject] $ cmd.exe /C '"c:\java\apache-ant-1.8.2\bin\ant.bat -file build.xml "-DGERRIT_PATCHSET_UPLOADER=""Some Dude"" <somedude@hotmail.com>" -DGERRIT_CHANGE_URL=http://edo-git:8082/7 -DGERRIT_CHANGE_ID=I497fbd0d12d27ce4fa540a7cda578c1a41ced7ad -DGERRIT_CHANGE_NUMBER=7 "-DGERRIT_PATCHSET_UPLOADER_NAME=Some Dude" "-DGERRIT_CHANGE_SUBJECT=dont rely on the existence of local.properties" -DGERRIT_PATCHSET_UPLOADER_EMAIL=somedude@hotmail.com -DGERRIT_BRANCH=master -DGERRIT_REFSPEC=refs/changes/07/7/1 -DGERRIT_PATCHSET_NUMBER=1 "-DGERRIT_CHANGE_OWNER_NAME=Some Dude" -DGERRIT_PATCHSET_REVISION=497fbd0d12d27ce4fa540a7cda578c1a41ced7ad -DGERRIT_PROJECT=com.test.project "-DGERRIT_CHANGE_OWNER=""Some Dude"" <somedude@hotmail.com>" -DGERRIT_CHANGE_OWNER_EMAIL=somedude@hotmail.com -Dsdk.dir=c:/java/android-sdk-windows debug && exit %%ERRORLEVEL%%"'
      16:18:18  Buildfile: c:\temp\hudsonwork\gerrit\TestProject\build.xml
      16:18:19  
      16:18:19  BUILD FAILED
      16:18:19  Target "Dude" does not exist in the project "TestProject". 
      

      When I build the project without the gerrit-trigger plugin I get the following (correct) format.

      16:45:09  [TestProject] $ cmd.exe /C '"c:\java\apache-ant-1.8.2\bin\ant.bat -file build.xml -Dsdk.dir=c:/java/android-sdk-windows debug && exit %%ERRORLEVEL%%"'
      16:45:09  Buildfile: c:\temp\hudsonwork\gerrit\TestProject\build.xml
      

      Why are those attributes added in the first place? It would probably be easiest to just add a configuration switch to disable modification of the command line.

          [JENKINS-11779] Gerrit-plugin modifies ant command line which is not compatible on windows

          I did a bit of digging in the Jenkins source and it seems that this might not be a gerrit-trigger problem at all but rather some broken parameter escaping policy on windows. I ran the same hudson job on a mac and there (if I put a checkmark into the "escape parameters" option) it works. So maybe we need to raise a ticket against the core Jenkins.
          The other thing that I find weird is that actually only want to provide the GERRIT_REFSPEC variable to the get job. The way that its currently done creates this side effect that every Builder will not add those parameters (just like ant did in my example). The question is whether there isn't a different way to do that.

          Rainer Burgstaller added a comment - I did a bit of digging in the Jenkins source and it seems that this might not be a gerrit-trigger problem at all but rather some broken parameter escaping policy on windows. I ran the same hudson job on a mac and there (if I put a checkmark into the "escape parameters" option) it works. So maybe we need to raise a ticket against the core Jenkins. The other thing that I find weird is that actually only want to provide the GERRIT_REFSPEC variable to the get job. The way that its currently done creates this side effect that every Builder will not add those parameters (just like ant did in my example). The question is whether there isn't a different way to do that.

          dan twining added a comment -

          re: "...some broken parameter escaping policy on windows. I ran the same hudson job on a mac..."

          It's a conflict between the way that jenkins launches ant on Windows, with

          cmd.exe /C '"ant.bat ....

          Whereas on other OSes it's just

          ant ....

          This additional quoting on Windows then conflicts with the quotes in the GERRIT paramaters (whether escaped or not).

          The proper fix would seem to be to find some way to get Jenkins to launch ant consistently across all platforms, but I don't know if that's possible. In the meantime, turning off / tailoring the variables being put in by Gerrit would help.

          dan twining added a comment - re: "...some broken parameter escaping policy on windows. I ran the same hudson job on a mac..." It's a conflict between the way that jenkins launches ant on Windows, with cmd.exe /C '"ant.bat .... Whereas on other OSes it's just ant .... This additional quoting on Windows then conflicts with the quotes in the GERRIT paramaters (whether escaped or not). The proper fix would seem to be to find some way to get Jenkins to launch ant consistently across all platforms, but I don't know if that's possible. In the meantime, turning off / tailoring the variables being put in by Gerrit would help.

          Nothize T added a comment -

          The fix may need to go after JENKINS-7053.

          Nothize T added a comment - The fix may need to go after JENKINS-7053 .

          Olivier Croquette added a comment - Here is possibly a workaround for this issue too: http://ocroquette.wordpress.com/2013/09/18/string-quoting-issues-in-jenkins-using-the-gerrit-and-gradle-plugins/

          rin_ne added a comment -

          You can pass all parameters to ant via file (using '-propertyfile' option) if you use the below plugin.
          https://wiki.jenkins-ci.org/display/JENKINS/Export+Parameters+Plugin

          rin_ne added a comment - You can pass all parameters to ant via file (using '-propertyfile' option) if you use the below plugin. https://wiki.jenkins-ci.org/display/JENKINS/Export+Parameters+Plugin

            rsandell rsandell
            rburgst2 Rainer Burgstaller
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: