循环访问 Azure Pipelines 变量组中的变量

pji*_*ers 2 yaml azure-devops azure-pipelines

azure-pipelines.yml文件中,如何枚举在 UI 中创建的“变量组”中定义的所有变量?

变量组

我想这样做,以便我可以.env在管道构建阶段将这些变量写入文件。

Krz*_*tof 5

管道中设置的变量与变量组中设置的变量在管道级别上没有区别。但您可以使用 Azure DevOps CLI 来实现您的目标。

请检查az pipelines 变量组变量列表

这就是从管道调用 CLI 的方式 - Azure Pipeline YAML 中的 Azure DevOps CLI

Linux 示例

steps:
# Updating the python version available on the linux agent
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.x'
    architecture: 'x64'

# Updating pip to latest
- script: python -m pip install --upgrade pip
  displayName: 'Upgrade pip'

# Updating to latest Azure CLI version.
- script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
  displayName: 'upgrade azure cli'

- script: az --version
  displayName: 'Show Azure CLI version'

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

- script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
  env:
    AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
  displayName: 'Login Azure DevOps Extension'

- script: az devops configure --defaults organization=https://dev.azure.com/{OrganizationName} project="Movie Search Web App" --use-git-aliases true
  displayName: 'Set default Azure DevOps organization and project'

- script: |
    az pipelines variable-group variable list --group-id 45
  displayName: 'Show variable group variables'

Run Code Online (Sandbox Code Playgroud)