由于 "powershell not found",Jenkins Pipeline powershell 步骤失败
Jenkins Pipeline powershell step fails due to "powershell not found"
我有一个 Jenkins 服务器 运行ning v2.107.3 和一个 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
的 "result" 和 Hello
的日志创建预期的文件。
根据您的错误,该进程可能无法找到 powershell 可执行文件,这意味着它是
- 没有完全路径
- 不在 PATH 环境变量中
如果您解决了其中任何一个问题,您的问题应该会得到解决。
我有一个 Jenkins 服务器 运行ning v2.107.3 和一个 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
的 "result" 和 Hello
的日志创建预期的文件。
根据您的错误,该进程可能无法找到 powershell 可执行文件,这意味着它是
- 没有完全路径
- 不在 PATH 环境变量中
如果您解决了其中任何一个问题,您的问题应该会得到解决。