Error: Unable to locate executable file: 'powershell' when running Azure CLI task in ADO pipeline

Error: Unable to locate executable file: 'powershell' when running Azure CLI task in ADO pipeline

我正在尝试 运行 管道中的 Azure CLI 任务并收到以下错误:

Starting: AzureCLI
==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell 
Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.1.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
##[error]Script failed with error: 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. Also check the file mode to verify the file is executable.
Finishing: AzureCLI

满足 https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops 中提到的先决条件。

**Pre-requisites mentioned in the ms site :**  
Microsoft hosted agents have Azure CLI pre-installed. However if you are using private agents, install Azure CLI on the computer(s) that run the build and release agent. If an agent is already running on the machine on which the Azure CLI is installed, restart the agent to ensure all the relevant stage variables are updated.

我没有使用任何私人代理。我正在使用免费订阅。

pipeline yaml 中的任务如下:

 - task: AzureCLI@2
  inputs:
    azureSubscription: 'Free Trial(<My Subscription id>)'
    scriptType: 'ps'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az --version
      az account show

为什么代理在其系统中找不到 powershell!! 这是一个错误吗?

谢谢!

您好,请尝试不使用“scriptType”并将 CLI 版本更改为 1,请参阅以下脚本,

 - task: AzureCLI@1
  inputs:
    azureSubscription: 'Free Trial(<My Subscription id>)'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az --version
      az account show

我认为您可能正在使用 Linux 代理,例如 'ubuntu-latest'。尝试将其改回 AzureCLI@2 并设置 scriptType: pscorescriptType: ps 不适用于 Linux。

    - task: AzureCLI@2
      displayName: Azure CLI
      inputs:
        azureSubscription: 'sc-name'
        scriptType: pscore
        scriptLocation: inlineScript
        inlineScript: |
          az account show