powershell - 由于“找不到powershell”,Jenkins Pipeline powershell 步骤失败
问题描述
我有一个运行 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 可执行文件,这意味着它是
- 未完全路径
- 不在 PATH 环境变量中
如果您修复其中任何一个,您的问题应该得到解决。
推荐阅读
- python - 如果存在匹配的维度(python/numpy),则无法创建参差不齐的数组
- oracle - 无法通过 shell 执行 .sql 来生成 csv 文件
- javascript - 如何使包含图像的整个刺痛模式在加载时可见?
- ffmpeg - ffmpeg 比例、重叠和不透明度
- python - 如何在 django 中阻止对其他登录用户的页面访问?
- go - Golang接口转换错误:缺少方法
- amazon-web-services - 带有授权者的 AWS REST API
- flutter - 如何使用 Dart 从 Flutter 中的 Firestore 子集合访问和获取数据?
- python - 在使用 selectKbest 进行特征选择时,我们可以对训练集和测试集使用相同的代码吗?它会提供相同的功能吗?
- docker - Jenkins 在 docker 中构建并复制工件