Dynamically generate variable group names in Azure Pipelines

I want to dynamically generate a variable group name on Azure pipelines, based on a variable that is coming from a variable group. I found several questions related to this, but none seems to address this specific use case.

So far, this has been working for us with the following code:

variables:
  - group: release

jobs:
- job: blue
  condition: eq(variables['deployment'], 'blue')
  variables:
  - group: blue-vars
  steps:
    - template: ../templates/some-code.yml

- job: green
  condition: eq(variables['deployment'], 'green')
  variables:
  - group: green-vars
  steps:
    - template: ../templates/some-code.yml

But now we need to extend this implementation, and we will have 10-12 jobs from whose only one will execute, according to the $(deployment) variable (coming from the release variable group). That is ugly, and difficult to maintain if we will need 10-12 blocks doing the exact same, with the same variables having different values, so I would like to refactor this solution.

I tried the obvious solution (below), but it doesn’t work most likely because the $(deployment) variable is only available on runtime, and needs to be available on compilation time.

- job: a_single_colour_1
  variables:
  - group: $(deployment)-vars
  steps:
    - template: ../templates/some-code.yml

I tried with compile-time expressions, but it seems that variables coming from variable groups are not resolved before compiling the expressions, so the below attempt is also failing:

- job: a_single_colour_2
  variables:
  - ${{ if eq(variables['deployment'], 'blue') }}:
    - group: blue-vars
  - ${{ if eq(variables['deployment'], 'green') }}:
    - group: green-vars
  steps:
    - template: ../templates/some-code.yml

After going through the documentation, I decided to use runtime expressions – as shown below – but it fails due to an error in the YAML (seems not to be supported):

 job: a_single_colour_3
  variables:
  - $[ if eq(variables['deployment'], 'blue') ]:
    - group: blue-vars
  - $[ if eq(variables['deployment'], 'green') ]:
    - group: green-vars
  steps:
    - template: ../templates/some-code.yml

Lastly, I tried to use a job template (code below), and I can see clearly that the variable $(deployment) is also not being resolved, causing a compile-time error due to the incompatible value for the deployment parameter.

On the main pipeline

- template: job_template.yml
  parameters: 
    deployment: $(deployment)

job_template.yml

parameters:
- name: deployment
  type: string
  values:
  - green
  - blue

jobs:
- job: a_single_colour_4
  variables:
  - name: deployment
    value: ${{ parameters.deployment }}
  - ${{ if eq(variables['deployment'], 'blue') }}:
    - group: blue-vars
  - ${{ if eq(variables['deployment'], 'green') }}:
    - group: green-vars
  steps:
    - template: ../templates/some-code.yml

Any idea how can I achieve what I want?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật