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

Cannot use spaces in groovy script parameters

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      The issue is caused by oversimplified parameters parsing implementation in this class: https://github.com/jenkinsci/groovy-plugin/blob/master/src/main/java/hudson/plugins/groovy/Groovy.java

              //Add groovy parameters
              if(parameters != null) {
                  StringTokenizer tokens = new StringTokenizer(parameters);
                  while(tokens.hasMoreTokens()) {
                      list.add(Util.replaceMacro(tokens.nextToken(),vr));
                  }
              }
      

      I would suggest to switch to org.apache.commons.exec.CommandLine.parse(..) method from Apache commons-exec.
      Not ideal, I know, but probably the best possible option if parsing command-line is inevitable.

      Is anyone interested in the patch? It would be very straightforward.

        Attachments

          Issue Links

            Activity

            Hide
            vjuranek vjuranek added a comment -

            ups, not intended to close it... Due to lack of time I didn't tested any other libraries and use proposed commons-exec, however this lib is IMHO far from perfect as it e.g. doesn't handle backslashed spaces (e.g. -cp /path/to/my\ groovy/libs splits into 3 args), but this is not subject of this issue and PR should be sent against used library.

            @enterit - please test JENKINS-23617 branch if it fixes your usecase, if yes I'll marge it to main branch and release

            Show
            vjuranek vjuranek added a comment - ups, not intended to close it... Due to lack of time I didn't tested any other libraries and use proposed commons-exec , however this lib is IMHO far from perfect as it e.g. doesn't handle backslashed spaces (e.g. -cp /path/to/my\ groovy/libs splits into 3 args), but this is not subject of this issue and PR should be sent against used library. @enterit - please test JENKINS-23617 branch if it fixes your usecase, if yes I'll marge it to main branch and release
            Hide
            vjuranek vjuranek added a comment -

            Merged into master branch and released in 1.19.

            Show
            vjuranek vjuranek added a comment - Merged into master branch and released in 1.19.
            Hide
            nigel_charman nigel_charman added a comment -

            Hi, Using 1.20, I'm unable to get parameters with spaces working. I've tried with double and single quotes around the parameter. Can you advise how to get spaces working? thanks

            Show
            nigel_charman nigel_charman added a comment - Hi, Using 1.20, I'm unable to get parameters with spaces working. I've tried with double and single quotes around the parameter. Can you advise how to get spaces working? thanks
            Hide
            danielbeck Daniel Beck added a comment -

            Jira is not a support site. Please ask in #jenkins on Freenode, or on the jenkinsci-users mailing list.

            Show
            danielbeck Daniel Beck added a comment - Jira is not a support site. Please ask in #jenkins on Freenode, or on the jenkinsci-users mailing list.
            Hide
            vjuranek vjuranek added a comment -

            @nigel_charman: there are two parameters options, Groovy parameters - parameter for groovy executable and Script parameters - parameters for script. It was implemented only for the first one, Groovy parameters. I've created JENKINS-24757 for allowing spaces also in Script parameters.

            Show
            vjuranek vjuranek added a comment - @nigel_charman: there are two parameters options, Groovy parameters - parameter for groovy executable and Script parameters - parameters for script. It was implemented only for the first one, Groovy parameters . I've created JENKINS-24757 for allowing spaces also in Script parameters .

              People

              • Assignee:
                vjuranek vjuranek
                Reporter:
                enterit enterit
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: