microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.42k stars 2.58k forks source link

[BUG]: can't run with task `AzureCLI@2` #19985

Closed ozbillwang closed 1 week ago

ozbillwang commented 3 weeks ago

New issue checklist

Task name

AzureCLI@2

Task version

2

Issue Description

This task works fine last month. But when today I run a pipeline with it, I got error

Use the sample code from the official document https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-cli-v2?view=azure-pipelines#examples

- task: AzureCLI@2
  displayName: Azure CLI
  inputs:
    azureSubscription: <Name of the Azure Resource Manager service connection>
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
      az --version
      az account show

i got the error

image

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

ubuntu 18.04

Relevant log output

Starting: Azure CLI
==============================================================================
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.241.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
/agent/externals/node20_1/bin/node -v
/agent/externals/node20_1/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /agent/externals/node20_1/bin/node)
##[error]Azure CLI 2.x is not installed on this machine.
##[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.
    at Object._which [as which] (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/2.241.0/node_modules/azure-pipelines-task-lib/internal.js:348:23)
    at WindowsPowerShell.<anonymous> (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/2.241.0/src/ScriptType.js:55:35)
    at Generator.next (<anonymous>)
    at fulfilled (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/2.241.0/src/ScriptType.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Finishing: Azure CLI


### Full task logs with system.debug enabled

<details>
  <pre> [REPLACE THIS WITH YOUR INFORMATION] </pre>
</details>

### Repro steps

_No response_
v-schhabra commented 2 weeks ago

Hi @ozbillwang Could you please change the script type from PowerShell to PowerShell Core as PowerShell script doesnt work with Linux agents. Please refer the doc for more info: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-cli-v2?view=azure-pipelines&viewFallbackFrom=azure-devops#task-inputs

ozbillwang commented 2 weeks ago

Same issue.

Currently I run a test.

with Microsoft managed agent (default agent pool), it works fine. I check its ubuntu release, it is 22.04. The task AzureCLI@2 works fine directly

mine is private agent pool, built on ubuntu 18.04 and the task is failed recently.

I am going to upgrade the private agent poool to 22.04, and will update the result

v-schhabra commented 2 weeks ago

@ozbillwang Could you please update if your task works fine after upgrading the agent (ubuntu) version to 22.04?

v-schhabra commented 1 week ago

@ozbillwang Please share the latest updates?

ozbillwang commented 1 week ago

@ozbillwang Please share the latest updates?

No difference.

Finally, I figured it out. The AzureCLI@2 task doesn't handle the installation of the Azure CLI. It assumes that the Azure CLI is already installed.

After adding a new task (show code below) before it, the AzureCLI@2 task runs fine now.

            - task: Bash@3
              displayName: InstallAzureCLI
              inputs:
                targetType: "inline"
                script: |
                  sudo apt-get -y install build-essential
                  curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
                  az --version
ozbillwang commented 1 week ago

my recommend is to update the related document https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-cli-v2?view=azure-pipelines and mention azure cli should be already installed on the Azure devops agent (if private agent), then you can use this task

v-schhabra commented 1 week ago

Hi @ozbillwang Please check this doc, here it is mentioned to install Azure CLI on the self hosted agent machine. https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV2/Readme.md