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

Gradle plugin fails to quote parameters without whitespace when containing input/output redirection symbols, e.g. in XML strings

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • gradle-plugin
    • None
    • Windows Server 2008 R2
      Jenkins 1.424.6
      Jenkins Gradle Plugin 1.12

      Gradle plugin explicitly passes job parameters to the "cmd.exe /c gradle.bat" call.

      If one of these arguments looks like XML, but does not contain whitespace, it is not quoted. This leads to problems with input/output redirection symbols (less-than, greater-than)

      Example String Parameter value:

      <fail>
      

      Results in the following build output:

      [workspace] $ cmd.exe /C C:\path\to\gradle.bat -Dfoo=<fail> -i && exit %%ERRORLEVEL%%
      The system cannot find the file specified.
      Build step 'Invoke Gradle script' changed build result to FAILURE
      Build step 'Invoke Gradle script' marked build as failure
      Notifying upstream projects of job completion
      

      Real world example:
      Copy artifacts plugin's "Latest successful build" has the value:

      <StatusBuildSelector/>
      

      This results in "File not found" errors on Windows Server. Not tested on Linux.

          [JENKINS-13412] Gradle plugin fails to quote parameters without whitespace when containing input/output redirection symbols, e.g. in XML strings

          Daniel Beck added a comment -

          It's not just real XML that's a problem here. Values such as `foo>bar` will also get interpreted as output redirection. Example:

          cmd.exe /c script.bat -Dfoo>bar
          

          This will redirect script.bat -Dfoo output to a file named bar.

          The calls in the examples fail, because there's no file named fail or StatusBuildSelector/, but the output issue is still unfixed. While this requires someone to explicitly enter parameter values such as this (instead of plugin use), and I don't have a good example, it should still be fixed.

          Daniel Beck added a comment - It's not just real XML that's a problem here. Values such as `foo>bar` will also get interpreted as output redirection. Example: cmd.exe /c script.bat -Dfoo>bar This will redirect script.bat -Dfoo output to a file named bar . The calls in the examples fail, because there's no file named fail or StatusBuildSelector/ , but the output issue is still unfixed. While this requires someone to explicitly enter parameter values such as this (instead of plugin use), and I don't have a good example, it should still be fixed.

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/hudson/plugins/gradle/Gradle.java
          http://jenkins-ci.org/commit/gradle-plugin/8571382e23a33604148e7012ddcb95a43482c256
          Log:
          Fix JENKINS-13412

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/hudson/plugins/gradle/Gradle.java http://jenkins-ci.org/commit/gradle-plugin/8571382e23a33604148e7012ddcb95a43482c256 Log: Fix JENKINS-13412

          Daniel Beck added a comment -

          1.16 fails for arguments that contain both spaces and angle brackets.

          [Gradle] - Launching build.
          [workspace] $ cmd.exe /C D:\jenkins\tools\Gradle-1.0-RC-1\bin\gradle.bat -Dtwo="<foo/>" "-Done=foo bar" '-Dthree="<foo> <bar> </foo>"' -i && exit %%ERRORLEVEL%%
          < was unexpected at this time.
          Build step 'Invoke Gradle script' changed build result to FAILURE
          

          Daniel Beck added a comment - 1.16 fails for arguments that contain both spaces and angle brackets. [Gradle] - Launching build. [workspace] $ cmd.exe /C D:\jenkins\tools\Gradle-1.0-RC-1\bin\gradle.bat -Dtwo= "<foo/>" "-Done=foo bar" '-Dthree= "<foo> <bar> </foo>" ' -i && exit %%ERRORLEVEL%% < was unexpected at this time. Build step 'Invoke Gradle script' changed build result to FAILURE

          I don't reproduce it.
          Maybe I don't understand very well.
          Could you attach your job configuration file (to have all information configuration)?

          Gregory Boissinot added a comment - I don't reproduce it. Maybe I don't understand very well. Could you attach your job configuration file (to have all information configuration)?

          Daniel Beck added a comment - - edited

          Nothing in the job configuration. Those are job arguments with the following values, one per line:

          <foo/>
          foo bar
          <foo> <bar> </foo>
          

          The first and second are handled properly, but the third, containing both spaces and XML brackets is quoted twice. That might be the cause of the problem.

          I cannot reproduce it on my Windows system without Jenkins etc. right now, I'll let you know what I find out.

          To reproduce my production problem, use Copy Artifacts plugin and a Build Selector job parameter that is set to "Specific Build". Then the XML value produced isn't handled properly by the Gradle program call.

          Daniel Beck added a comment - - edited Nothing in the job configuration. Those are job arguments with the following values, one per line: <foo/> foo bar <foo> <bar> </foo> The first and second are handled properly, but the third, containing both spaces and XML brackets is quoted twice. That might be the cause of the problem. I cannot reproduce it on my Windows system without Jenkins etc. right now, I'll let you know what I find out. To reproduce my production problem, use Copy Artifacts plugin and a Build Selector job parameter that is set to "Specific Build". Then the XML value produced isn't handled properly by the Gradle program call.

          Thanks for your comment.
          Unfortunately, I can't reproduce an error with the latest value in my environment with the Gradle plugin.
          I'm closing the issue.
          Do no hesitate to reopen it when you would successes to isolate the problem with only the Gradle plugin.

          Gregory Boissinot added a comment - Thanks for your comment. Unfortunately, I can't reproduce an error with the latest value in my environment with the Gradle plugin. I'm closing the issue. Do no hesitate to reopen it when you would successes to isolate the problem with only the Gradle plugin.

          Daniel Beck added a comment -

          Minimal example that fails on Windows (Jenkins 1.447.1, Jenkins Gradle Plugin 1.16) when using default parameter value, which was specified in previous comments:

          <?xml version='1.0' encoding='UTF-8'?>
          <project>
            <actions/>
            <description></description>
            <keepDependencies>false</keepDependencies>
            <properties>
              <hudson.model.ParametersDefinitionProperty>
                <parameterDefinitions>
                  <hudson.model.StringParameterDefinition>
                    <name>FOO</name>
                    <description></description>
                    <defaultValue>&lt;foo&gt; &lt;bar/&gt; &lt;/foo&gt;</defaultValue>
                  </hudson.model.StringParameterDefinition>
                </parameterDefinitions>
              </hudson.model.ParametersDefinitionProperty>
            </properties>
            <scm class="hudson.scm.NullSCM"/>
            <canRoam>true</canRoam>
            <disabled>false</disabled>
            <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
            <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
            <triggers class="vector"/>
            <concurrentBuild>false</concurrentBuild>
            <builders>
              <hudson.plugins.gradle.Gradle>
                <description></description>
                <switches></switches>
                <tasks></tasks>
                <rootBuildScriptDir></rootBuildScriptDir>
                <buildFile></buildFile>
                <gradleName>Gradle 1.0 RC3</gradleName>
                <useWrapper>false</useWrapper>
              </hudson.plugins.gradle.Gradle>
            </builders>
            <publishers/>
            <buildWrappers/>
          </project>
          

          Build log:

          Started by user anonymous
          [Gradle] - Launching build.
          [fail gradle call] $ cmd.exe /C C:\JenkinsHome\tools\Gradle_1.0_RC3\bin\gradle.bat '-DFOO="<foo> <bar/> </foo>"' && exit %%ERRORLEVEL%%
          < was unexpected at this time.
          Build step 'Invoke Gradle script' changed build result to FAILURE
          Build step 'Invoke Gradle script' marked build as failure
          Finished: FAILURE
          

          Daniel Beck added a comment - Minimal example that fails on Windows (Jenkins 1.447.1, Jenkins Gradle Plugin 1.16) when using default parameter value, which was specified in previous comments: <?xml version= '1.0' encoding= 'UTF-8' ?> <project> <actions/> <description></description> <keepDependencies> false </keepDependencies> <properties> <hudson.model.ParametersDefinitionProperty> <parameterDefinitions> <hudson.model.StringParameterDefinition> <name>FOO</name> <description></description> <defaultValue>&lt;foo&gt; &lt;bar/&gt; &lt;/foo&gt;</defaultValue> </hudson.model.StringParameterDefinition> </parameterDefinitions> </hudson.model.ParametersDefinitionProperty> </properties> <scm class= "hudson.scm.NullSCM" /> <canRoam> true </canRoam> <disabled> false </disabled> <blockBuildWhenDownstreamBuilding> false </blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding> false </blockBuildWhenUpstreamBuilding> <triggers class= "vector" /> <concurrentBuild> false </concurrentBuild> <builders> <hudson.plugins.gradle.Gradle> <description></description> <switches></switches> <tasks></tasks> <rootBuildScriptDir></rootBuildScriptDir> <buildFile></buildFile> <gradleName>Gradle 1.0 RC3</gradleName> <useWrapper> false </useWrapper> </hudson.plugins.gradle.Gradle> </builders> <publishers/> <buildWrappers/> </project> Build log: Started by user anonymous [Gradle] - Launching build. [fail gradle call] $ cmd.exe /C C:\JenkinsHome\tools\Gradle_1.0_RC3\bin\gradle.bat '-DFOO= "<foo> <bar/> </foo>" ' && exit %%ERRORLEVEL%% < was unexpected at this time. Build step 'Invoke Gradle script' changed build result to FAILURE Build step 'Invoke Gradle script' marked build as failure Finished: FAILURE

          Jesse Glick added a comment -

          According to http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html#sec:gradle_properties_and_system_properties you can define environment variables (if I read it right) such as ORG_GRADLE_PROJECT_key=val which would be much less prone to misinterpretation than -Dkey=val command-line properties.

          Jesse Glick added a comment - According to http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html#sec:gradle_properties_and_system_properties you can define environment variables (if I read it right) such as ORG_GRADLE_PROJECT_key=val which would be much less prone to misinterpretation than -Dkey=val command-line properties.

          I was able to reproduce this bug, running a windows jenkins and creating a gradle job with string parameter "<foo> <bar>"
          using debugger, I ended in java.lang.ProcessBuilder, that seems to be the root cause, by adding those single quotes but not escaping the square bracket characters

          maybe related to http://bugs.sun.com/view_bug.do?bug_id=6468220
          "
          On Windows platform Runtime.exec(String[] cmdarray) does not pass correctly command line arguments, if one of them contains double quotes (")
          "

          I'm not sure about the environment variable option Jesse suggested. Would like gradleware advice here

          Nicolas De Loof added a comment - I was able to reproduce this bug, running a windows jenkins and creating a gradle job with string parameter "<foo> <bar>" using debugger, I ended in java.lang.ProcessBuilder, that seems to be the root cause, by adding those single quotes but not escaping the square bracket characters maybe related to http://bugs.sun.com/view_bug.do?bug_id=6468220 " On Windows platform Runtime.exec(String[] cmdarray) does not pass correctly command line arguments, if one of them contains double quotes (") " I'm not sure about the environment variable option Jesse suggested. Would like gradleware advice here

          Code changed in jenkins
          User: Nicolas De Loof
          Path:
          src/main/java/hudson/plugins/gradle/Gradle.java
          http://jenkins-ci.org/commit/gradle-plugin/3ce68c23921a59b02d0159d9f7038941b88afada
          Log:
          [FIXED JENKINS-13412] use hudson.util.ArgumentListBuilder#toWindowsCommand


          You received this message because you are subscribed to the Google Groups "Jenkins Commits" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-commits+unsubscribe@googlegroups.com.
          For more options, visit https://groups.google.com/groups/opt_out.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Nicolas De Loof Path: src/main/java/hudson/plugins/gradle/Gradle.java http://jenkins-ci.org/commit/gradle-plugin/3ce68c23921a59b02d0159d9f7038941b88afada Log: [FIXED JENKINS-13412] use hudson.util.ArgumentListBuilder#toWindowsCommand – You received this message because you are subscribed to the Google Groups "Jenkins Commits" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-commits+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out .

            gbois Gregory Boissinot
            danielbeck Daniel Beck
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: