8

TL;DR

Is it possible to have a parameter and its values in a template YAML and have the main YAML read the list and present them in a drop-down when preparing to run a pipeline?

Very similar to the MS example of "Variable reuse", shown here.

# File: vars.yml
variables:
  favoriteVeggie: 'brussels sprouts'
# File: azure-pipelines.yml

variables:
- template: vars.yml  # Template reference

steps:
- script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.

Details

I have a list of some 50 values that grow from week to week. When an Ops person runs my pipeline, I would like them to select a value from a drop-down.

This can be achieved simply by specifying a parameter block in the pipeline YAML file(azure-pipeline.yml):

parameters:
- name: subscription
  displayName: Subscription Name
  type: string
  default: sub A
  values:
  - sub A
  - sub B
  - sub C
  - sub D

This gives me the drop-down in the UI:

Run pipeline drop-down

In my example above, there are only four values, however, we have over 50 values (subscriptions) and growing. I am trying to devise a way where 1) Ops won't have to edit the pipeline 2) keeping the main pipeline file concise.

I know there is currently no way to dynamically populate the list of values, but what I am looking at doing is to use a template YAML file that will have just the values and it will read the template, populating the drop-down. It is then a fairly straight forward task to have a script/pipeline dynamically update the values in the template file.

Reading the docs and some blogs, I believe this may be possible, but I haven't managed to crack it.

It appears that the parameter block can take "any YAML structure", although I haven't been able to find a suitable example of this. Amongst other things, this is what I have tried:

templates/subscriptions.yml

- name: subscription
  displayName: Subscription Name
  type: string
  default: sub A
  values:
  - sub A
  - sub B
  - sub C
  - sub D``

azure-pipelines.yml

...
template: templates/subscriptions.yml
  parameters:
    subscription: []

stages:
- stage: Example
  displayName: 1.0 Demo Stage
  jobs:
...

I wonder if my issue is that I need the parameters to be read right at the start and this isn't supported. It only works in a stage/job etc.

If anyone has any ideas, I'd be grateful if you could point me in the right direction.

T.I.A.

woter324
  • 2,608
  • 5
  • 27
  • 47
  • Well parameters and variables are quite different things so I don't think it's possible to do what you describe. You can probably manually parse the vars yaml but this is also likely a dead-end. 50 vars anyway rather sound like a design issue, I'd rather try coming up with new templates and scenarios - but it's hard to say without seeing actual pipelines. – psfinaki May 05 '21 at 06:59
  • Hi @Kevin Lu-MSFT I came up with a different approach. Using a folder named the same as the subscription and then using Git to detect new folder or files inside the folder. – woter324 May 26 '21 at 10:41
  • Hi @woter324. Glad to know that you could find the method. You could share it in answer and accept the answer. This will be helpful to other users. – Kevin Lu-MSFT May 27 '21 at 07:34
  • @woter324 were you able to find a solution for this use case? Could you please mention what was workaround you went ahead with as I have a very similar requirement currently – rsram312 Feb 25 '22 at 22:02

1 Answers1

2

Based on your requirement, I am afriad that there is no such mehtod could meet your requirements for the time being.

The yaml template in Azure Devops needs to be referenced by the main yaml(e.g. azure-pipelines.yml) to pass the value.

Please refer to this doc: Yaml schema.

The parameters field in YAML cannot call the parameter template in yaml. Therefore, if only pure parameters are defined, they cannot be called in the main yaml.

This method is only supported by variables.

But your requirement makes sense. I suggest that you could submit a suggestion ticket in Our UserVoice Site.

patriml
  • 472
  • 3
  • 9
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28