3

According to the official documentation at https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops-2019 the Azure DevOps Server 2019 on-prem supports everything.

Yet, I cannot make it work with a simple yaml template with parameters.

Here is my yaml template (named prepare-sonar-qube.yml):

parameters:
- name: projectKey
  type: string

- name: projectName
  type: string
  default: ${{ parameters.projectKey }}

- name: useDotCover
  type: boolean
  default: false

steps:
- template: install-java.yml

- task: SonarQubePrepare@4
  displayName: 'Prepare SQ Analysis'
  inputs:
    SonarQube: 'SonarQube'
    scannerMode: 'MSBuild'
    projectKey: parameters.projectKey
    projectName: parameters.projectName
    ${{ if parameters.useDotCover }}: 
      extraProperties: |
        sonar.cs.dotcover.reportsPaths=$(Common.TestResultsDirectory)\coverage\*.CoverageResult.html
        sonar.inclusions=**/*.cs
    ${{ if !parameters.useDotCover }}: 
      extraProperties: |
        sonar.cs.opencover.reportsPaths=$(Common.TestResultsDirectory)\coverage\*.CoverageResult.xml 
        sonar.inclusions=**/*.cs

Here is the azure-pipelines.yml:

trigger:
- master

name: 1.0.$(Date:yy)$(DayOfYear)$(Rev:.r)

jobs:
- job: Build
  pool:
    demands: DotNetFramework
  workspace:
    clean: all
  variables:
  - template: variables.yml  
  steps:
  - template: prepare-sonar-qube.yml
    parameters:
      projectKey: logs2db

...

Running the build I get the following lovely error message:

/prepare-sonar-qube.yml (Line: 2, Col: 1): A sequence was not expected

enter image description here

So what am I doing wrong? (Besides being a loyal TFS customer who got stuck with an outdated on-prem Azure DevOps Server 2019 that does not seem to go anywhere when compared against the ever evolving hosted Azure DevOps Services)

mark
  • 59,016
  • 79
  • 296
  • 580

3 Answers3

1

You do not did anything wrong. Need sorry to say, that is our document issue.

The syntax you are trying is our new richer YAML syntax feature, which haven't supported in Azure DevOps Server 2019 until now.

To let public know and avoid this before we make changes to document, I create a thread and announce this unsupport here.


At present, the on-prem server only support the older syntax, where defaults are declared as a mapping without type or value constraints:

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

Or

parameters:
  solution: ''
Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • How do I make one parameter default to the value of another parameter? – mark Mar 09 '20 at 04:03
  • @mark, what do you mean of **default to the value of another parameter**? – Mengdi Liang Mar 09 '20 at 04:09
  • If I want the parameter X to take the value of the parameter Y by default, i.e. when parameter X is not explicitly given. – mark Mar 09 '20 at 04:34
  • @mark. If what you want is as your definition shared above, they are both in same template.yml file. Afraid to say, it does not support defined in `Parameters`. We haven't support compile A parameter's value then assign it to another parameter B( same in azure devops service). You have to do this with tasks like command line and powershell. – Mengdi Liang Mar 09 '20 at 05:02
-1

This looks like a simple indentation issue.

Here's a snip from one of my working templates.

parameters:
  - name: sln
    type: string
    default: ''
  - name: slnName
    type: string
    default: ''
  - name: proj
    type: string
    default: ''

Try using space space - name: [name]

Josh Gust
  • 4,102
  • 25
  • 41
-1

This is a bit of an old question now, but a similar question has been addressed in this StackOverflow post that explains how using Runtime Parameters in Azure DevOps Server 2019 is not supported in that version.

If you try to review the Runtime Parameters doc in MS Learn, when you select the Azure DevOps Server 2019 option, it will show the warning that "The requested page is not available for Azure DevOps Server 2019. You have been redirected to the newest product version this page is available for."

enter image description here

Chioke Aarhus
  • 333
  • 3
  • 10