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

Azure DevOps hosted agent pipeline "Unable to locate executable file: 'Powershell'

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

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

然后重启主机。

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

新版本打破了这个任务。

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

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

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

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

pwsh.exe is not available on the agent machine

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

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

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

您需要完全像这样设置 azCLI 任务:

azureSubscription:

scriptType: 

workingDirectory:

scriptLocation: inlineScript

inlineScript: