英文:
How to dynamically select between variable groups when running an Azure pipeline
问题
我们有一个要使用不同配置运行的流水线。因此,我们已经定义了一组变量组,如下所示:
- 配置前缀 - 配置 1
- 配置前缀 - 配置 2
- 配置前缀 - 配置 3
每个组都定义了相同的变量,但具有不同的值。然后我们在流水线中引用它们:
parameters:
- name: configName
displayName: Configuration
type: string
values:
- '配置 1'
- '配置 2'
- '配置 3'
variables:
- group: "配置前缀 - ${{ parameters.configName }}"
steps:
- script: |
echo "--------------------------------"
echo "使用配置 ${{ parameters.configName }}"
echo "--------------------------------"
echo "var1: '$(var1)'"
echo "var2: '$(var2)'"
echo "var3: '$(var3)'"
echo "--------------------------------"
运行流水线时,我们可以选择配置并运行。但是,要添加新的配置,我们必须添加新的变量组,然后修改流水线。
是否可能使流水线动态呈现可用的配置而无需硬编码它们?例如,如果我们可以在某个地方定义组列表,或者只需使流水线查找具有前缀的所有组。
英文:
We have a pipeline that we want to run with different configurations. So we have defined a set of variable groups like
- Config Prefix - Config 1
- Config Prefix - Config 2
- Config Prefix - Config 3
Each group define the same variables with different values. And then we reference them in the pipeline:
parameters:
- name: configName
displayName: Configuration
type: string
values:
- 'Config 1'
- 'Config 2'
- 'Config 3'
variables:
- group: "Config Prefix - ${{ parameters.configName }}"
steps:
- script: |
echo "--------------------------------"
echo "Use config for ${{ parameters.configName }}"
echo "--------------------------------"
echo "var1: '$(var1)'"
echo "var2: '$(var2)'"
echo "var3: '$(var3)'"
echo "--------------------------------"
On running the pipeline we can select configuration and run. But in order to add a new configuration we must add the new variable group and then modify the pipeline.
Would it be possible to have the pipeline dynamically present the available configurations without hard coding them? Eg if we could define the list of groups somewhere or just have the pipeline find all groups with the prefix
答案1
得分: 1
答案是不可以,在Azure Pipelines中是不可能的。
你可以创建一个自动化程序,每隔一段时间检查你的变量组,如果有一个带有你的前缀的新组被添加,自动化程序将编辑YAML文件。
英文:
The answer is no, it's impossible in Azure Pipelines.
You can do an automation that check your variable groups each X time, if a new group with your prefix added the automation will edit the yaml.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论