'Jenkins not finding powershell
I'm getting this error when I tried to run a Windows Powershell command in my biuld. I don't know how to add Powershell.exe to this? This was a plugin and I have no idea where it's located or how to use it.
[DeploymentTest] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& '/tmp/jenkins8870821876113230026.ps1'"
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
. . .
Caused: java.io.IOException: Cannot run program "powershell.exe" (in directory "/var/lib/jenkins/workspace/DeploymentTest"): error=2, No such file or directory
Solution 1:[1]
You are running it on a Linux box.Please switch over to a Windows box as you need Windows to run powershell.
Solution 2:[2]
If you're running dotnet/powershell on Linux, use a shell step and call the linux powershell executable /usr/bin/pwsh within it.  Here's an example working for me on a dotnet5 debian container:
stage('PreBuild') {
  steps {
    sh '''
      wget -v  https://aka.ms/install-artifacts-credprovider.ps1
      /usr/bin/pwsh -File ./install-artifacts-credprovider.ps1 -AddNetfx
      dotnet --version
      # reset the nuget credentials
      dotnet nuget update source "infrastructure"
    '''
  }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Ravindranath Barathy | 
| Solution 2 | andrew lorien | 
