azure - 为什么 Azure Pipeline PowerShell 任务无法识别 Azure cli?

标签 azure azure-devops azure-pipelines azure-cli

我在 Windows Server Agent 上安装了 Azure cli,它在 cmd/PowerShell 中运行良好。但是当我想在 Azure Pipeline 中的 PowerShell 任务上使用 Azure cli 时,它不起作用。

错误消息是:“az”未被识别为内部或外部命令。

cmd 代理示例:

enter image description here

Azure Pipeline 上的任务代码示例:

- powershell: |
        echo "*********" | az devops login --organization https://dev.azure.com/*****
  displayName: 'Login on Azure CLI

我检查Path环境变量,甚至更新管道中的变量以确保一切正常,但没有任何变化。

最佳答案

我已按照以下步骤从 azure 管道执行 az 命令。检查您是否已执行所有这些步骤并能够解决问题。

首先,我使用以下命令在 Windows 计算机上安装 Azure CLI。

$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://azcliprod.blob.core.windows.net/msi/azure-cli-2.49.0.msi -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; Remove-Item .\AzureCLI.msi

接下来,我使用以下配置在虚拟机上安装了 devops 代理。

enter image description here

配置管道时,请确保选择正确的代理池。 In my case it is default. 要进行测试,请添加 powershell task使用命令 az login --service-principal -u $(appid) -p $(passwd) --tenant $(tenant) 的任务管道。运行管道并验证输出。 enter image description here

如果仍然遇到问题,请检查环境变量路径以验证是否包含 AZ CLI 路径。您可以从管道运行 echo $env:PATH 进行检查。 enter image description here 如果 AZ CLI 路径不存在,请将其添加到系统变量中并再次验证。

关于azure - 为什么 Azure Pipeline PowerShell 任务无法识别 Azure cli?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76372192/

相关文章:

docker - 无法在Azure发布管道的App Service内部创建Docker网络

azure-devops - 基于 azure devops yml 的管道中的 git commit 和 git tag

azure - 如何在azure二头肌中引用模块中的父资源?

excel - Azure DevOps-发布任务构建失败

powershell - Windows Azure Powershell 部署错误 - "The remote server returned an unexpected response"

azure-devops - Azure Pipeline DevOps 中的条件默认值

azure - 通过 Bastion Host 配置 VMSS 创建的 Windows VM

找不到 Azure 管道 : error MSB4019 WebApplication. 目标

Azure Kubernetes - Prometheus 自动服务发现?

azure - 无法打开 Azure 机器学习工作台