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

Incorrect quoting of environment variables

    Details

    • Similar Issues:

      Description

      To reproduce:
      Add a build parameter with a value that contains a space.
      The plugin will pass:
      "-Dvar=value"
      The quoting for that statement results in Grails parsing anything after the space incorrectly.
      Possible fix:
      "-Dvar=\"value\""

        Attachments

          Activity

          Hide
          geogriffin Kurt Devlin added a comment -

          I experienced this when we tried using the Build User Vars Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin)

          The new system properties are escaped correctly in other plugins, but the Grails plugin breaks with an incorrectly quoted BUILD_USER parameter. See a snippet of the log results below.

          [workspace] $ /apps/grails-2.2.3/bin/grails -DBUILD_USER_LAST_NAME=Doe -DBUILD_USER_FIRST_NAME=John "-DBUILD_USER=John Doe" -DBUILD_USER_EMAIL=John.Doe@myCompany.com -DBUILD_USER_ID=jDoe dev war myProject.war --non-interactive

          Loading Grails 2.2.3
          Configuring classpath
          Running pre-compiled script
          Error Script not found: Doe

          Pulling out the Grails plugin and calling Grails directly with Execute Shell, I used the "Possible Fix" suggested in the description and it worked.

          Putting -DBUILD_USER=\"John Doe\" in the shell command, translated to '-DBUILD_USER="John' 'Doe"' being displayed in the output of the script and the build executed successfully.

          Show
          geogriffin Kurt Devlin added a comment - I experienced this when we tried using the Build User Vars Plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin ) The new system properties are escaped correctly in other plugins, but the Grails plugin breaks with an incorrectly quoted BUILD_USER parameter. See a snippet of the log results below. [workspace] $ /apps/grails-2.2.3/bin/grails -DBUILD_USER_LAST_NAME=Doe -DBUILD_USER_FIRST_NAME=John "-DBUILD_USER=John Doe" -DBUILD_USER_EMAIL=John.Doe@myCompany.com -DBUILD_USER_ID=jDoe dev war myProject.war --non-interactive Loading Grails 2.2.3 Configuring classpath Running pre-compiled script Error Script not found: Doe Pulling out the Grails plugin and calling Grails directly with Execute Shell, I used the "Possible Fix" suggested in the description and it worked. Putting -DBUILD_USER=\"John Doe\" in the shell command, translated to '-DBUILD_USER="John' 'Doe"' being displayed in the output of the script and the build executed successfully.
          Hide
          geogriffin Kurt Devlin added a comment -

          Raised the Priority of this. It is not cosmetic and there isn't a workaround. We are trying to use the user build parameters for additional Jenkins functionality, but were forced to remove them (as would anyone with parameters with spaces).

          Show
          geogriffin Kurt Devlin added a comment - Raised the Priority of this. It is not cosmetic and there isn't a workaround. We are trying to use the user build parameters for additional Jenkins functionality, but were forced to remove them (as would anyone with parameters with spaces).
          Hide
          geogriffin Kurt Devlin added a comment -

          JENKINS-24629 and JENKINS-22508 are the same issue.

          Show
          geogriffin Kurt Devlin added a comment - JENKINS-24629 and JENKINS-22508 are the same issue.
          Hide
          ydubreuil Yoann Dubreuil added a comment -

          Unfortunately, argument quoting is done correctly by the Grails plugin. There's a bug report covering this problem in the grails command line tool: https://jira.grails.org/browse/GRAILS-11351

          Faking the grails command with this shell script:

          #!/bin/bash
          
          cat /proc/$$/cmdline | xxd 
          
          while [[ $# -ne 0 ]]; do
            echo $1
            shift
          done
          

          produces this output when launched by the Jenkins Grails plugin :

           
          [workspace] $ grails "-Dgrails.work.dir=dir with spaces" compile --non-interactive --plain-output
          0000000: 2f62 696e 2f62 6173 6800 2f68 6f6d 652f  /bin/bash./home/
          0000010: 6475 6475 2f62 696e 2f67 7261 696c 7300  dudu/bin/grails.
          0000020: 2d44 6772 6169 6c73 2e77 6f72 6b2e 6469  -Dgrails.work.di
          0000030: 723d 6469 7220 7769 7468 2073 7061 6365  r=dir with space
          0000040: 7300 636f 6d70 696c 6500 2d2d 6e6f 6e2d  s.compile.--non-
          0000050: 696e 7465 7261 6374 6976 6500 2d2d 706c  interactive.--pl
          0000060: 6169 6e2d 6f75 7470 7574 00              ain-output.
          -Dgrails.work.dir=dir with spaces
          compile
          --non-interactive
          --plain-output
          

          meaning argument quoting is done correctly.

          Show
          ydubreuil Yoann Dubreuil added a comment - Unfortunately, argument quoting is done correctly by the Grails plugin. There's a bug report covering this problem in the grails command line tool: https://jira.grails.org/browse/GRAILS-11351 Faking the grails command with this shell script: #!/bin/bash cat /proc/$$/cmdline | xxd while [[ $# -ne 0 ]]; do echo $1 shift done produces this output when launched by the Jenkins Grails plugin : [workspace] $ grails "-Dgrails.work.dir=dir with spaces" compile --non-interactive --plain-output 0000000: 2f62 696e 2f62 6173 6800 2f68 6f6d 652f /bin/bash./home/ 0000010: 6475 6475 2f62 696e 2f67 7261 696c 7300 dudu/bin/grails. 0000020: 2d44 6772 6169 6c73 2e77 6f72 6b2e 6469 -Dgrails.work.di 0000030: 723d 6469 7220 7769 7468 2073 7061 6365 r=dir with space 0000040: 7300 636f 6d70 696c 6500 2d2d 6e6f 6e2d s.compile.--non- 0000050: 696e 7465 7261 6374 6976 6500 2d2d 706c interactive.--pl 0000060: 6169 6e2d 6f75 7470 7574 00 ain-output. -Dgrails.work.dir=dir with spaces compile --non-interactive --plain-output meaning argument quoting is done correctly.
          Hide
          jspiewak Joshua Spiewak added a comment -

          This has nothing to do with the Build User Vars Plugin for us. With version 1.6.3 of the Grails Plugin the command line is generated as:

          "/var/lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive
          

          while version 1.7 is:

          "/var/lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" "-Dgrails.work.dir=/var/lib/jenkins/workspace/TS/Dev Unit Tests//target" -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive
          

          Would it be possible for the Jenkins Grails plugin to perform escaping when generating the command line to Grails?

          For example:

          "/var/lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" '-Dgrails.work.dir="/var/lib/jenkins/workspace/TS/Dev\ Unit\ Tests//target"' -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive
          
          Show
          jspiewak Joshua Spiewak added a comment - This has nothing to do with the Build User Vars Plugin for us. With version 1.6.3 of the Grails Plugin the command line is generated as: "/ var /lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive while version 1.7 is: "/ var /lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" "-Dgrails.work.dir=/ var /lib/jenkins/workspace/TS/Dev Unit Tests //target" -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive Would it be possible for the Jenkins Grails plugin to perform escaping when generating the command line to Grails? For example: "/ var /lib/jenkins/workspace/TS/Dev Unit Tests/skillz/grailsw" '-Dgrails.work.dir= "/ var /lib/jenkins/workspace/TS/Dev\ Unit\ Tests //target" ' -Duser.timezone=UTC -Dgrails.env=test compile --non-interactive
          Hide
          richardjq Richard Quintin added a comment - - edited

          Description states:
          Possible fix: "-Dvar=\"value\""

          It seems like a better fix would be: -Dvar="value"

          You could even do that in every case (whether the value has spaces or not).

          Show
          richardjq Richard Quintin added a comment - - edited Description states: Possible fix: "-Dvar=\"value\"" It seems like a better fix would be: -Dvar="value" You could even do that in every case (whether the value has spaces or not).
          Hide
          jfaenomoto João Enomoto added a comment -

          Upvoting this issue. We are running Grails Plugin + GitHub Pull Request build Plugin. When a build is triggered by GitHub, there are a lot of parameters which are put into a build and are propagated to Grails Plugin (which by itself I don't know if it's a feature or a bug).

          Since usually one or more parameters have spaces on them, build breaks on every action it attempts to make.

          Workaround has been running Grails builds steps as a shell script, which is not optimal but works.

          Show
          jfaenomoto João Enomoto added a comment - Upvoting this issue. We are running Grails Plugin + GitHub Pull Request build Plugin. When a build is triggered by GitHub, there are a lot of parameters which are put into a build and are propagated to Grails Plugin (which by itself I don't know if it's a feature or a bug). Since usually one or more parameters have spaces on them, build breaks on every action it attempts to make. Workaround has been running Grails builds steps as a shell script, which is not optimal but works.
          Hide
          jonaldomo John Moses added a comment -

          I submitted a PR https://github.com/jenkinsci/grails-plugin/pull/12 to work around this by suppressing the -D build environment variables.

          I am using the Github pull request builder plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin to run test-app and was running into the same issues as others. I am not using any of the variables that the ghprb plugin passes in so I added an option to suppress -D build environment variables. When this option is checked none of the -D variables are passed to grails allowing the build with grails plugin to run the targets as expected.

          If you want to test it out to see if it works for you, you can download it from here http://jmoses.co/data/grails.hpi and install it manually http://stackoverflow.com/questions/14950408/how-to-install-a-plugin-in-jenkins-manually

          Show
          jonaldomo John Moses added a comment - I submitted a PR https://github.com/jenkinsci/grails-plugin/pull/12 to work around this by suppressing the -D build environment variables. I am using the Github pull request builder plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin to run test-app and was running into the same issues as others. I am not using any of the variables that the ghprb plugin passes in so I added an option to suppress -D build environment variables. When this option is checked none of the -D variables are passed to grails allowing the build with grails plugin to run the targets as expected. If you want to test it out to see if it works for you, you can download it from here http://jmoses.co/data/grails.hpi and install it manually http://stackoverflow.com/questions/14950408/how-to-install-a-plugin-in-jenkins-manually

            People

            • Assignee:
              jeffg2one jeffg2one
              Reporter:
              asedlackparts Aron Sedlack
            • Votes:
              3 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: