11

I am trying to run an Azure CLI task in pipeline and getting the following error :

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

The pre-requisites mentioned in https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops is fulfilled.

**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.

I am not using any private agents. I am using a free subscription.

The task in pipeline yaml is as :

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

Why is the agent not able to find powershell in its system!! Is this a bug?

Thanks!

Nilotpal
  • 3,237
  • 4
  • 34
  • 56

2 Answers2

15

I think you might be using a Linux agent such as 'ubuntu-latest'. Try changing it back to AzureCLI@2 and set scriptType: pscore. scriptType: ps doesn't work on Linux.

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

Hi try without "scriptType" and change the CLI version to 1, Please see the below script,

 - task: AzureCLI@1
  inputs:
    azureSubscription: 'Free Trial(<My Subscription id>)'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az --version
      az account show
Inzi
  • 348
  • 3
  • 12
  • ##[error]Script failed with error: Error: Input required: scriptType – Nilotpal Jul 11 '21 at 06:20
  • @Nilotpal I have updaetd the answer. can u please check ? – Inzi Jul 11 '21 at 07:35
  • Yes This works. Awesome. I have another issue, where i am not able to run pipeline build from the inline script. I would create another question on that. In case you have any idea on that, would be great! Thanks for answering this! – Nilotpal Jul 11 '21 at 07:56
  • @Nilotpal can u send the question link pls – Inzi Jul 11 '21 at 08:01
  • https://stackoverflow.com/questions/68334416/error-the-requested-resource-requires-user-authentication-in-azurecli-task-bui – Nilotpal Jul 11 '21 at 08:16
  • Hi I'm also facing above exception. After I changed to AzureCLI@1 I got another exception. **ERROR: the following arguments are required: --source/-s, --destination/-d.** Refer my Question: https://stackoverflow.com/questions/70461134/azure-cli-2-x-is-not-installed-on-this-machine – Sivakumar Dec 23 '21 at 11:04