错误:在 ADO 管道中运行 Azure CLI 任务时无法找到可执行文件:“powershell”

Nil*_*pal 15 azure-cli azure-devops azure-pipelines azure-pipelines-yaml

我尝试在管道中运行 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://learn.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
Run Code Online (Sandbox Code Playgroud)

满足https://learn.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.
Run Code Online (Sandbox Code Playgroud)

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

pipeline yaml 中的任务如下:

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

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

谢谢!

小智 20

我认为您可能正在使用 Linux 代理,例如“ubuntu-latest”。尝试将其更改回 AzureCLI@2 并设置scriptType: pscore. scriptType: ps在 Linux 上不起作用。

    - task: AzureCLI@2
      displayName: Azure CLI
      inputs:
        azureSubscription: 'sc-name'
        scriptType: pscore
        scriptLocation: inlineScript
        inlineScript: |
          az account show
Run Code Online (Sandbox Code Playgroud)


Inz*_*nzi 4

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

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