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

Powershell command was not found on a different OS slave machine

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: powershell-plugin
    • Environment:
      # Master Slave
      - OS: Windows10
      - Jenkins: org.jenkins-ci.main:jenkins-war:2.222.1
      - Powershell plugin: 1.4

      # Slave
      - OS: macOS Catalina
      - pwsh: PowerShell 7.0.0
      - PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
    • Similar Issues:

      Description

      When I tried to use powershell-plugin on each slave machines(Win and Mac) from Win master machine, just MacOS slave machine had an error because no such found `pwsh` command.

      Here's the error log details.

      [test] $ pwsh -NonInteractive -File /var/folders/7s/624v46091sdgcf0b1qt98v6hz4r8lc/T/jenkins7665436840857556803.ps1
      FATAL: コマンドの実行に失敗しました
      java.io.IOException: error=2, No such file or directory
      	at java.lang.UNIXProcess.forkAndExec(Native Method)
      	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
      	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
      Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to mac
      		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1788)
      		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
      		at hudson.remoting.Channel.call(Channel.java:998)
      		at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1057)
      		at hudson.Launcher$ProcStarter.start(Launcher.java:454)
      		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
      		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
      		at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      		at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
      		at hudson.model.Build$BuildExecution.build(Build.java:206)
      		at hudson.model.Build$BuildExecution.doRun(Build.java:163)
      		at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
      		at hudson.model.Run.execute(Run.java:1856)
      		at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      		at hudson.model.ResourceController.execute(ResourceController.java:97)
      		at hudson.model.Executor.run(Executor.java:428)
      Caused: java.io.IOException: Cannot run program "pwsh" (in directory "/Users/****/workspace/test"): error=2, No such file or directory
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
      	at hudson.Proc$LocalProc.<init>(Proc.java:252)
      	at hudson.Proc$LocalProc.<init>(Proc.java:221)
      	at hudson.Launcher$LocalLauncher.launch(Launcher.java:936)
      	at hudson.Launcher$ProcStarter.start(Launcher.java:454)
      	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1316)
      	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1269)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
      	at hudson.remoting.Request$2.run(Request.java:369)
      	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      Build step 'PowerShell' marked build as failure
      Finished: FAILURE
      

       

        Attachments

          Activity

          Hide
          ceztko Francesco Pretto added a comment - - edited

          This is not an issue only when using jenkins in a slave machine. In my master machine I have the same exact issue and the problem is clearly that the PATH variable doesn't include /usr/local/bin directory for the spawned daemon that run jenkins. Setting PATH+EXTRA as Konstantin Kutsner mentioned can't be a solution because the environment variable is modified too late and that settings doesn't influence resolving of shells location.

          If installed jenkins with homebrew, one workaround is to edit ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist to specify a full list of paths like the following:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
          <plist version="1.0">
            <dict>
              <key>EnvironmentVariables</key>
              <dict>
                 <key>PATH</key>
                 <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
              </dict>
              <key>Label</key>
              <string>homebrew.mxcl.jenkins-lts</string>
              <key>ProgramArguments</key>
              <array>
                <string>/usr/libexec/java_home</string>
                <string>-v</string>
                <string>1.8</string>
                <string>--exec</string>
                <string>java</string>
                <string>-Dmail.smtp.starttls.enable=true</string>
                <string>-jar</string>
                <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string>
                <string>--httpListenAddress=127.0.0.1</string>
                <string>--httpPort=8080</string>
              </array>
              <key>RunAtLoad</key>
              <true/>
            </dict>
          </plist>
          

          Then you can restart the service or the machine.

          The pipeline plugin could indeed also be improved so it attempts to resolve location fo pwsh with more fallbacks. For example it could (on unix platforms) try to find with this order:
          1) Result of /usr/bin/env pwsh
          2) Result of which pwsh
          3) Direct path /usr/local/bin/pwsh if existing
          4) Direct path /usr/bin/pwsh if existing

          Of course the result can be cached so this resolution is not repeated everytime a pwsh directive is used.

          Show
          ceztko Francesco Pretto added a comment - - edited This is not an issue only when using jenkins in a slave machine. In my master machine I have the same exact issue and the problem is clearly that the PATH variable doesn't include /usr/local/bin directory for the spawned daemon that run jenkins. Setting PATH+EXTRA as Konstantin Kutsner mentioned can't be a solution because the environment variable is modified too late and that settings doesn't influence resolving of shells location. If installed jenkins with homebrew, one workaround is to edit ~/Library/LaunchAgents/homebrew.mxcl.jenkins-lts.plist to specify a full list of paths like the following: <?xml version= "1.0" encoding= "UTF-8" ?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" > <plist version= "1.0" > <dict> <key> EnvironmentVariables </key> <dict> <key> PATH </key> <string> /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin </string> </dict> <key> Label </key> <string> homebrew.mxcl.jenkins-lts </string> <key> ProgramArguments </key> <array> <string> /usr/libexec/java_home </string> <string> -v </string> <string> 1.8 </string> <string> --exec </string> <string> java </string> <string> -Dmail.smtp.starttls.enable=true </string> <string> -jar </string> <string> /usr/local/opt/jenkins-lts/libexec/jenkins.war </string> <string> --httpListenAddress=127.0.0.1 </string> <string> --httpPort=8080 </string> </array> <key> RunAtLoad </key> <true/> </dict> </plist> Then you can restart the service or the machine. The pipeline plugin could indeed also be improved so it attempts to resolve location fo pwsh with more fallbacks. For example it could (on unix platforms) try to find with this order: 1) Result of /usr/bin/env pwsh 2) Result of which pwsh 3) Direct path /usr/local/bin/pwsh if existing 4) Direct path /usr/bin/pwsh if existing Of course the result can be cached so this resolution is not repeated everytime a pwsh directive is used.
          Hide
          kkutsner Konstantin Kutsner added a comment -

          I ran into similar issue and it was struggling to run "pwsh" on mac slave. I think iti s related to "PATH" environment variable.  "pwsh" was installed into "/usr/local/bin" but the "PATH" had only "/usr/bin:/bin:/usr/sbin:/sbin:" You can try to run a build step e.g. 
          sh "/usr/local/bin/pwsh -Command \"Get-Host | Select-Object Version\""
          just to make sure you can run powershell using the full path to the executable. I ended up with modifying slave configuration to have PATH variable have "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin". Note that thier fancy syntax PATH+EXTRA did not work so I just added PATH with all paths I needed.

          Show
          kkutsner Konstantin Kutsner added a comment - I ran into similar issue and it was struggling to run "pwsh" on mac slave. I think iti s related to "PATH" environment variable.  "pwsh" was installed into "/usr/local/bin" but the "PATH" had only "/usr/bin:/bin:/usr/sbin:/sbin:" You can try to run a build step e.g.  sh "/usr/local/bin/pwsh -Command \"Get-Host | Select-Object Version\"" just to make sure you can run powershell using the full path to the executable. I ended up with modifying slave configuration to have PATH variable have "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin". Note that thier fancy syntax PATH+EXTRA did not work so I just added PATH with all paths I needed.
          Hide
          rbshinde Rajesh Shinde added a comment -

          I am also facing the same issue. My Jenkin Master is linux and slave is Windows Server 2012

          Show
          rbshinde Rajesh Shinde added a comment - I am also facing the same issue. My Jenkin Master is linux and slave is Windows Server 2012

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tanishi Shintaro Tanikawa
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: