运行 来自 Azure DevOps 管道 YAML 文件的 `az artificats` 命令

Running `az artificats` commands from Azure DevOps pipeline YAML file

在我的 Azure Pipelines YAML 文件中,我使用 Bash 任务来 运行 一个 Python 脚本,该脚本在 Azure Artifacts(通用包)上缓存 CocoaPods 库。我假设 Azure DevOps 虚拟机上的 Azure 命令行工具会安装最新的 Azure 扩展。我错了

我的 Python 脚本调用 az artifacts universal downloadaz artifacts universal publish 等命令。这对我的 Mac 非常有效。 Microsoft 的 VM 上没有那么多。

如有任何建议,我们将不胜感激。

##[section]Starting: Bash
==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.159.3
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
Script contents:
./cache_pods.py Debug
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /Users/runner/runners/2.160.1/work/_temp/d0fd889d-a201-42ac-aad6-45ee3eca0532.sh
ERROR: az: 'artifacts' is not in the 'az' command group. See 'az --help'.

ERROR: az: 'artifacts' is not in the 'az' command group. See 'az --help'.

您需要先安装 Azure DevOps Extension,然后再使用 az artifacts 命令。 详情请参考Azure DevOps CLI in Azure Pipeline YAML

steps:
- script: az extension add -n azure-devops
  displayName: 'Install Azure DevOps Extension'

请将此添加到您的 yaml 中,然后重试。希望这会奏效。

得到同样的问题花了一个小时得到解决方案: 没有扩展名,它不能工作所以尝试按照以下步骤操作:

首先尝试点击下面的命令找到扩展

az extension add --name azure-devops

然后检查扩展是否可用:

例如。对于管道:

az extension add --name azure-devops

和 运行 命令