首页 > 解决方案 > 由于“找不到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

创建预期的文件,带有“结果”0Hello.

标签: powershelljenkinsjenkins-pluginsjenkins-pipeline

解决方案


根据您的错误,该进程可能找不到 powershell 可执行文件,这意味着它是

  1. 未完全路径
  2. 不在 PATH 环境变量中

如果您修复其中任何一个,您的问题应该得到解决。


推荐阅读