如何在运行Azure管道时动态选择变量组。

huangapple go评论52阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月10日 20:54:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218674.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定