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

Cannot have spaces in path to PowerShell script

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • powershell-plugin
    • Jenkins 2.32.2, Windows 7 Pro. Chrome 56

      My PowerShell script was in the directory "C:\Program Files (x86)\Jenkins\scripts\MyScript.ps1" but was not being executed. When I removed the double-quotes an exception was thrown:
      {{The term 'C:\Program' is not recognized as the name of a cmdlet, function, scri
      pt file, or operable program. Check the spelling of the name, or if a path was
      included, verify that the path is correct and try again.
      At C:\Windows\TEMP\hudson8395162481558588519.ps1:1 char:11
      + C:\Program <<<< Files (x86)\Jenkins\scripts\MyScript.ps1
      + CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandN
      otFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
      }}

      When I moved the script to a path without spaces D:\Jenkins\scripts it worked fine (without double-quotes).

      A brief investigation makes me think it's the Jenkins FileInfo.getRemote method returning the script path in full if it's surrounded in quotes but then the CommandInterpreter.buildCommandLine override is then enclosing the same path in single quotes when creating the array.

      The result is a path of '"C:\Program Files (x86)\Jenkins\scripts\MyScript.ps1"' being created. When the quotes are removed in the configuration getRemote just returns C:\Program which becomes 'C:\Program'.

            Unassigned Unassigned
            witchdr Andy Jones
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: