I have a Jenkins agent running on Windows 2016, and intend to run PowerShell steps on it.
For some reason, despite my global system PATH having the PowerShell path in it, I cannot run a `powershell()` step unless I explicitly set a PATH in my Jenkinsfile:
environment {
PATH = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0"
}
If I don't, I get an error:
C:\Jenkins\workspace\test_ps_remoting@tmp\durable-1c380b43\powershellWrapper.ps1 : The term 'powershell' is not recognized as the name of a cmdlet, function, script 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:\Jenkins\workspace\test_ps_remoting@tmp\durable-1c380b43\powershellHelper.ps1:54 char:9
+ & { & $MainScript | Out-FileNoBom -Writer $OutputWriter } *>&1 | ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (powershell:String) [powershellWrapper.ps1], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,powershellWrapper.ps1
Oddly, it looks like the agent _is_ running PS correctly, because that's a PS error, but the process it spawns can't.
If I catch the 3 temporary files that Jenkins drops on the agent, I can run them manually just fine, as the Jenkins service user, so the system PATH is definitely correct.
I have added the WindowsPowerShell directory to both the System's PATH, and the service account user's PATH, neither makes a difference.
I recently posted the question on SO, but only got a workaround, not a solution.
Thanks,
Mark