我有一个嵌套的 Azure DevOps YAML 管道:
---
name: Some Release Pipeline
trigger: none
variables:
- group: "DEV VARIABLE GROUP" # This is the environment variable library
stages:
- stage: Stage1
displayName: "Stage 1"
dependsOn: []
jobs:
- template: /pipelines/pipeline_templates/sometemplate.yml
我想做的是在任何环境中重用这个发布管道。理想情况下,我会设置一个管道变量“组名称”,然后将其分配给该组。像这样的东西:
---
name: Some Release Pipeline
trigger: none
variables:
- group: "$(group-name)" # This is the environment variable library
stages:
- stage: Stage1
displayName: "Stage 1"
dependsOn: []
jobs:
- template: /pipelines/pipeline_templates/sometemplate.yml
然而,这似乎不起作用。无奈之下,我尝试了多种方法:
- Using
${{ group-name }}
- 我尝试使用以下方法将组名称作为参数传递:
jobs:
- template: /pipelines/pipeline_templates/sometemplate.yml
parameters:
variablegroup: $(group-name)
然后将其设置在作业中的 sometemplate.yml 中。例如:
jobs:
- job: Job1
variables:
- group: ${{ parameters.variablegroup }}
然而,这也不起作用。
- 我尝试过使用插入 https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#insertion (
{{ insert }}
)按照建议here https://github.com/microsoft/azure-pipelines-yaml/issues/340。但是,要么我不知道如何正确使用插入,要么这不起作用,因为我总是遇到某种形式的验证错误。
根据this https://stackoverflow.com/questions/59173157/pass-a-variable-group-name-using-rest-api-azure-devops, and this https://stackoverflow.com/questions/52372291/azure-devops-vsts-link-variable-group-through-yaml, and this https://stackoverflow.com/questions/56224798/can-group-name-variable-be-dynamic-in-azure-pipelines, and this https://github.com/MicrosoftDocs/vsts-docs/issues/3702看来不可能。
我想知道是否有人找到了解决方案(除了调用 DevOps REST API 的非常混乱的解决方法之外)?