Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins Pipeline powershell步骤失败,原因是;“未找到powershell”;_Powershell_Jenkins_Jenkins Plugins_Jenkins Pipeline - Fatal编程技术网

Jenkins Pipeline powershell步骤失败,原因是;“未找到powershell”;

Jenkins Pipeline powershell步骤失败,原因是;“未找到powershell”;,powershell,jenkins,jenkins-plugins,jenkins-pipeline,Powershell,Jenkins,Jenkins Plugins,Jenkins Pipeline,我有一个运行v2.107.3的Jenkins服务器和一个Windows代理节点。一个简单的测试powershell管道失败,因为它找不到“powershell” 这是我的测试管道: pipeline { stages { stage('test') { steps { powershell(script:'Write-Output Hello') } } } } 代理

我有一个运行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环境变量中

  • 如果您解决了这两个问题中的任何一个,您的问题都应该得到解决。

    听起来您的环境变量不好。完整路径
    powershell.exe
    。另外:
    &{&$
    只是..为什么?@theincorgible1这与我无关。这就是powershell插件所做的。我只是指定了
    powershell('write-host hello')
    。其余的都是包装器废话。@theincorgible1你关于ENV的提示是正确的。我添加了
    路径=“C:\Windows\System32\WindowsPowerShell\v1.0”
    到管道似乎已经修复了它。将其作为答案发布,我会接受它。他们的样板非常奇怪,但我很高兴我能提供帮助奇怪的是,Powershell有一个系统级路径条目,但java进程似乎没有得到它。现在,在我的管道中设置它可以解决问题。@Cylindric听起来像它不是读取系统环境变量,只是读取用户和/或进程我不得不取消接受这个答案,因为我意识到我不能在多代理管道中真正设置全局路径,因为我不想弄乱其他代理设置,而且它们甚至不是所有的Windows代理。我还怀疑我永远不会得到一个未打开的问题的答案。没关系。结果是另一个Jenkins管理员加入了全局环境变量设置路径为
    /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
    。这很有趣。