【问题标题】:Error: Unable to locate executable file: 'powershell' when running Azure CLI task in ADO pipeline错误:在 ADO 管道中运行 Azure CLI 任务时无法找到可执行文件:“powershell”
【发布时间】:2021-07-11 03:12:35
【问题描述】:

我正在尝试在管道中运行 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.

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

管道 yaml 中的任务如下:

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

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

谢谢!

【问题讨论】:

    标签: azure-devops azure-pipelines azure-cli azure-pipelines-yaml


    【解决方案1】:

    我认为您可能正在使用诸如“ubuntu-latest”之类的 Linux 代理。尝试将其改回 AzureCLI@2 并设置 scriptType: pscorescriptType: ps 在 Linux 上不起作用。

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

    【讨论】:

    • 这是记录在here
    【解决方案2】:

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

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

    【讨论】:

    • ##[error]Script failed with error: Error: Input required: scriptType
    • @Nilotpal 我已经更新了答案。你能检查一下吗?
    • 是的,这行得通。惊人的。我还有另一个问题,我无法从内联脚本运行管道构建。我会就此提出另一个问题。如果您对此有任何想法,那就太好了!感谢您回答这个问题!
    • @Nilotpal 可以发问题链接吗
    猜你喜欢
    • 2021-06-14
    • 2023-04-07
    • 2022-09-24
    • 1970-01-01
    • 2022-01-03
    • 2020-08-27
    • 2017-04-24
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多