J.D. Cain
J.D. Cain

Reputation: 659

YAML Pipeline Template Parameter Syntax

There are two documents on the Microsoft docs site which seem to declare different syntax for YAML template parameters.

I have not been able to deduce where the first one below is used, while the 2nd one works fine. I wanted to know if the version declaring type is deprecated.

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops-2019#template-expressions

parameters:
- name: 'solution'
  default: '**/*.sln'
  type: string

https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=example#template-references

parameters:
  name: ''
  testFile: ''

Upvotes: 0

Views: 1539

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18978

The scripts you shared, are actually the two syntax of the different usage scenarios of parameter.

Let's map them with classic UI. In msbuild task, there has one blank which required you input .sln/.csproj file path:

enter image description here

As normal, you do not need change this value manually if there's nothing special on path. Because it is injected automatically by system in the task.

This is exactly same thing the below YAML script do:

parameters:
- name: 'solution'
  default: '**/*.sln'
  type: string

When you configure this in YAML template, in most scenarios, you do not need configured the value in YAML again, except you want to change to another value.

That's also why we said the solution parameter is optional in doc:

enter image description here


Contrary to the above, parameters are required when using the following syntax:

parameters:
  name: ''
  testFile: ''

You must pass value from YAML at this time, or it will cause execution error. Because there's no any values injected for them from start to end.


I wanted to know if the version declaring type is deprecated.

Do you mean the task version declaring? If yes, NO, it does not be deprecated. And it is the required one that you must provided. Because different task version may has different task configuration and execution logic.

The one you saw in this doc, just be the shortcut format. See this tab. Until now, we only support below shortcut keywords, and they do not need version specified by user. Because they will automatically pick the default version value that our backend system defined:

Script => command-line task

bash => shell script task

pwsh/powershell => PowerShell task

publish => Publish Pipeline Artifact task

download => Download Pipeline Artifact task


Update on 3/9/2020:

parameters:
- name: 'solution'
  default: '**/*.sln'
  type: string

Above script is the richer YAML syntax which is the new feature we deployed recently, and it haven't supported in Azure devops server 2019 until now (3/9/2020).

For Azure devops server 2019, it only support the older syntax, where defaults are declared as a mapping without type or value constraints:

parameters:
  solution: '**/*.sln'

Upvotes: 2

Related Questions