Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why showing Unexpected value 'pool' error when put it into a template yaml file?

I am trying to learn azure devops yaml and uses template.

Here is my pipeline yaml (basically wants to set a parameter and call a template file):

trigger:
 branches:
   include:
     - master
 paths:
   exclude:
      - YAML/*

extends:
  template: azure-pipeline.yaml
  parameters:
      MergeSprintToMaster: false 

Here is my template file azure-pipeline.yaml, which contains all commons things:

parameters:
- name: MergeSprintToMaster # name of the parameter; required
  type: boolean # data type of the parameter; required
  default: false

pool:
  name: Azure Pipelines
  vmImage: 'windows-latest'
  demands:
  - msbuild
  - visualstudio
  - vstest

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU' 
  buildConfiguration: 'Release'

steps:
- task: AzureCLI@2

I got an validation error saying /YAML/azure-pipeline.yaml (Line: 11, Col: 1): Unexpected value 'pool'

What is wrong with the way I am trying to use yaml?

like image 943
daxu Avatar asked Jan 25 '23 18:01

daxu


2 Answers

Apparently you can't have the pool top-level in your template when the template is targeted by an extends. See https://developercommunity.visualstudio.com/content/problem/992713/unexpected-value-pool-when-extending-a-template.html and https://github.com/microsoft/azure-pipelines-yaml/issues/430

Use the following instead:

parameters:
- name: MergeSprintToMaster # name of the parameter; required
  type: boolean # data type of the parameter; required
  default: false

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU' 
  buildConfiguration: 'Release'
jobs:
- job:
  pool:
    name: Azure Pipelines
    vmImage: 'windows-latest'
    demands:
    - msbuild
    - visualstudio
    - vstest

  steps:
  - task: AzureCLI@2
like image 124
riQQ Avatar answered Jan 29 '23 12:01

riQQ


Product team have confirmed currently pool cannot be included in the top level pipeline when that pipeline uses extends:

https://github.com/MicrosoftDocs/azure-devops-docs/issues/7972#issuecomment-618988624

extends currently requires an explicit jobs: or stages: wrapper even in the case of a single job. The two rules are:

  1. If a pipeline contains extends, then only trigger, pr, schedule, and resources can appear at the top level alongside extends.
  2. If a pipeline template will be the target of extends, then it must have at least a jobs level specified.
like image 29
Cece Dong - MSFT Avatar answered Jan 29 '23 12:01

Cece Dong - MSFT