azure-devopsyamlbuild-pipeline

Azure Devops Build Pipeline - Unexpected value stages


I'm refactoring a pipeline to use a stage as template so I don't have duplicate code in my test-publish build pipeline and release build pipeline. But I get the error which I commented in the following .yml lines.

resources:
- repo: self
  clean: true

trigger:
  branches:
    include:
    - development

stages: # error on this line: unexpected value 'stages'
 - template: build-job.yml
 - stage: Publish
   jobs:
   - job: PublishClickOnce
     steps:
     - task: PublishSymbols@2
       displayName: 'Publish symbols path'
       inputs:
         SearchPattern: '**\bin\**\*.pdb'
         PublishSymbols: false
       continueOnError: true

The example provided by Microsoft:

# File: azure-pipelines.yml
trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

stages:
- stage: Install
  jobs: 
    - job: npminstall
      steps:
      - task: Npm@1
        inputs:
          command: 'install'
- template: templates/stages1.yml
- template: templates/stages2.yml

I checked against the documentation but can't see anything wrong with it. Can you point out my mistake and what I should change?


Solution

  • Azure Devops Build Pipeline - Unexpected value stages

    The error may be from the template. Since the template is directly nested under stages, you should make sure the template is also under the stage.

    Like the following YAML:

    resources:
    - repo: self
      clean: true
    
    trigger:
      branches:
        include:
        - master
    
    pool:
      vmImage: 'windows-latest'
    
    stages:
     - template: build-job.yml
     - stage: Publish
       jobs:
       - job: PublishClickOnce
         steps:
           - task: PowerShell@2
             inputs:
              targetType : inline
              script: |
                Write-Host "Hello world!"
    

    Then the build-job.yml:

    stages:
    - stage: test
      jobs:
      - job: test
        steps:
        - script: echo testdemo
        displayName: 'templateTest'
    

    It works fine on my side, you could check if it works for you.

    Besides, if you set the template is directly nested under steps, then the template should start with steps.

    If it not work for you, please share you detailed build error log in your question.

    Hope this helps.