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:
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.