0

I'm trying to get Azure DevOps pipelines to prompt for a version number when manually launching a pipeline (defined using the new YAML syntax).

Even when I define variables in the template, the launch screen says "This pipeline has no defined variables". How can I define variables so that they show up in the pipeline launch?

Current YAML definition contains:

variables:
  - name: versionName
    value: ''

These are not shown when launching the pipeline:

Running the pipeline

Sampo
  • 4,308
  • 6
  • 35
  • 51

2 Answers2

5

While Shayki's answer is correct for defining variables, what I was really looking for is runtime parameters.

With the following YAML definition:

parameters:
  - name: myParameter
    displayName: Description of myParameter
    default: defaultMyParameter
    type: string

it prompts for the parameter value when launching the pipeline:

Pipeline prompting for myParameter

The parameter must be referenced in the template using ${{ parameters.myParameter }}, the other variable syntaxes don't work.

Sampo
  • 4,308
  • 6
  • 35
  • 51
2

From the docs:

If a variable appears in the variables block of a YAML file, its value is fixed and can't be overridden at queue time. Best practice is to define your variables in a YAML file but there are times when this doesn't make sense. For example, you may want to define a secret variable and not have the variable exposed in your YAML. Or, you may need to manually set a variable value during the pipeline run.

You have two options for defining queue-time values. You can define a variable in the UI and select the option to Let users override this value when running this pipeline or you can use runtime parameters instead. If your variable is not a secret, the best practice is to use runtime parameters.

To set a variable at queue time, add a new variable within your pipeline and select the override option.

enter image description here

enter image description here

enter image description here

To allow a variable to be set at queue time, make sure the variable doesn't also appear in the variables block of a pipeline or job. If you define a variable in both the variables block of a YAML and in the UI, the value in the YAML will have priority.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114