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

Passing script parameters containing "|" works on Linux but fails on Windows

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When executing a Groovy script build step, where one of the "Script parameters" arguments contains a "|", the Groovy build step fails. Sample Groovy script (for Groovy 3.x; comment out lines 2 and 3 for lower versions):

      // Get dependencies
      @GrabConfig(systemClassLoader=true)
      @Grab('info.picocli:picocli-groovy:4.2.0')
      
      // Import external modules
      import groovy.cli.picocli.CliBuilder
      
      // Parse command line options
      def cli = new CliBuilder(name: 'theScript.groovy')
      cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show usage information')
      cli.r(type: String, longOpt: 'regex', required: true, args: 1, 'Regular expression (required)')
      def opts = cli.parse(args)
      opts || System.exit(1)
      if(opts.h) {
        cli.usage()
        System.exit(0)
      }
      println('Regex: ' + opts.r)
      

      With "Script parameters" given as "-r foo|bar", this executes the script on Linux and thus prints

      Regex: foo|bar

      while it fails on Windows with

      'bar' is not recognized as an internal or external command, operable program or batch file.

      which means the script isn't even executed. I also tried to quote the regex with single or double quotes and escape the "|" with "^" (CMD) or "`" (Powershell) without any luck.

      I would expect this to behave exactly the same on Linux and Windows.

        Attachments

          Activity

          dhs Dirk Heinrichs created issue -
          dhs Dirk Heinrichs made changes -
          Field Original Value New Value
          Priority Minor [ 4 ] Major [ 3 ]
          dhs Dirk Heinrichs made changes -
          Summary Passing script parameters with "|" works on Linux but fails Windows Passing script parameters with "|" works on Linux but fails on Windows
          dhs Dirk Heinrichs made changes -
          Summary Passing script parameters with "|" works on Linux but fails on Windows Passing script parameters containing "|" works on Linux but fails on Windows
          dhs Dirk Heinrichs made changes -
          Labels Security

            People

            Assignee:
            vjuranek vjuranek
            Reporter:
            dhs Dirk Heinrichs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: