我有一个运行 v2.107.3 版本的 Jenkins 服务器和一个 Windows 代理节点。一个简单的测试 PowerShell 流水线失败了,因为它找不到 "powershell"。
这是我的测试流水线:
pipeline {
stages {
stage('test') {
steps {
powershell(script:'Write-Output Hello')
}
}
}
}
代理的响应总是:
C:\Jenkins\workspace\test_ps_remoting@tmp\durable-ccca47a5\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-ccca47a5\powershellHelper.ps1:54 char:9
+ & { & $MainScript | Out-FileNoBom -Writer $OutputWriter } *>&1 | ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (powershell:String) [powershellWrapper.ps1], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,powershellWrapper.ps1
我已经成功获取了@tmp中运行的文件的副本,如果我手动执行这些步骤,它似乎完全正常:
. .\powershellHelper.ps1
Execute-AndWriteOutput -MainScript .\powershellWrapper.ps1 -OutputFile out.txt -LogFile log.txt -ResultFile result.txt
创建预期的文件,其“结果”为
0
,日志为Hello
。
powershell.exe
。另外:& { & $
这是为什么? - Maximilian Burszleypowershell('write-host hello')
。其余部分是包装器废话。 - CylindricPATH = "C:\Windows\System32\WindowsPowerShell\v1.0"
,似乎已经解决了问题。将其发布为答案,我会接受它。 - Cylindric