microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.19k stars 924 forks source link

YAML Extend Stage Template #568

Open deckerbr1979 opened 2 years ago

deckerbr1979 commented 2 years ago

Hello All,

Looking to try and get some help figuring out a solution to what seems like a simple task. I am trying to develop some extend YAML templates for security within our ADO pipelines but first I have to get passed this error I am experiencing.

The error being returned by ADO when I try to validate or run the pipeline is "/ADO_Stage_Restrictions_Dev.yml@AdoRestrictions (Line: 7, Col: 3): Unexpected value 'job'".

Working Extend Template YAML This template validates and executes without issue, which to me means I am successfully passing the stages object into the extends template

parameters:
  - name: stageObjs
    type: stageList
    default: []

stages:
- ${{ each stage in parameters.stageObjs }}:
    ${{ stage }}

Broken Extend Template YAML This template does not validate and throws the 'Unexpected value job' exception. based on the stage schema I would assume that I would be able to loop the jobs property within the stage.

parameters:
  - name: stageObjs
    type: stageList
    default: []

stages:
- ${{ each stage in parameters.stageObjs }}:
  - ${{ each job in stage.jobs }}:
      ${{ job }}

Build YAML The main yaml file that extends stages

resources:
  repositories:
    - repository: self
      type: git
      ref: refs/heads/Development

    - repository: AdoRestrictions
      type: git
      name: utl-yaml-templates
      ref: refs/heads/main

trigger: none

pool:
    name: PROD    

extends:
  template: ADO_Stage_Restrictions_Dev.yml@AdoRestrictions
  parameters:
    stageObjs:
      - stage: 'BuildStage'
        displayName: 'Build Test'
        jobs:
          - job: 'BuildJob'
            displayName: 'Build'
            steps:
            - task: PowerShell@2
              displayName: 'Hello World'
              inputs:
                targetType: inline
                script: |
                  Write-Host "Hello World"