Azure DevOps 托管代理管道“无法找到可执行文件:‘Powershell’

时间:2021-03-17 15:15:39

标签: powershell deployment azure-devops

Azure DevOps 部署代理(自托管在我们的一个 Windows VM 上)决定突然停止工作,在执行 IIS Web App Deploy 步骤时抛出此错误:

Error: Unable to locate executable file: 'powershell'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable.

最近有没有其他人收到过这个?

查看日志,有一个警告表明:

PowerShell Core (pwsh.exe) is not available on agent machine. Falling back to using Windows PowerShell (powershell.exe). This can cause reduced performance. Please install the newer version of PowerShell for improved performance.

此错误有些不对劲,因为 A) 我使用 Powershell 安装了代理,B) 我删除了该代理,并且在发生此错误后能够使用 PowerShell 重新安装它。

管道步骤本身与默认值保持不变,并且已经运行多年没有问题——这里是从 DevOps 生成的 YAML 来证明这一点(如果间距被 SO 弄乱了,请道歉):

steps:
- task: IISWebAppDeploymentOnMachineGroup@0
  displayName: 'IIS Web App Deploy'
  inputs:
       WebSiteName: '$(Parameters.WebsiteName)'
       TakeAppOfflineFlag: True
       XmlVariableSubstitution: True

4 个答案:

答案 0 :(得分:4)

新版本打破了这个任务。

https://github.com/microsoft/azure-pipelines-tasks/issues/14595

添加 ADO_FORCE_USE_7ZIP=true 作为管道变量。

答案 1 :(得分:1)

看来 IIS Web 部署任务已在 Azre 上更新。在发布日志中,我可以看到任务版本不再是 0.179.0,而是 0.184.0: image

我已经在主机上安装了 PowerShell Core (7.0.6) 并重新启动了它。不是它工作正常。

答案 2 :(得分:1)

<块引用>

pwsh.exe 在代理机器上不可用

最近更新了IIS web部署任务的版本。该任务将检查默认情况下是否有 powershell 7。如果没有,就会有这个警告。

enter image description here

要解决这个问题,您需要install powershell 7。安装Powershell 7并设置系统环境后,任务将使用Powershell 7。

设置系统环境:系统属性 -> 环境变量。

enter image description here

enter image description here

答案 3 :(得分:0)

我能够通过将默认 PowerShell 安装目录路径重新添加到系统 PATH 来解决此问题,如下所述:

https://stackoverflow.com/a/29778651/4822220

然后重新启动主机。

这实际上并没有解决问题,因为 Azure Pipeline 日志中仍然有警告 pwsh.exe is not available on the agent machine。请注意,Powershell 安装在默认目录中,但由于某些原因,DevOps 代理的部署脚本仍然无法找到它。

相关问题