16

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!

2 Answers 2

24

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
Sign up to request clarification or add additional context in comments.

2 Comments

This is documented here
I feel like this is more appropriate answer!
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

6 Comments

##[error]Script failed with error: Error: Input required: scriptType
@Nilotpal I have updaetd the answer. can u please check ?
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 can u send the question link pls
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.