Matthias Herrmann
Matthias Herrmann

Reputation: 2790

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?

Upvotes: 3

Views: 6883

Answers (2)

housten
housten

Reputation: 136

When I was refactoring from a job to a stages layout, I was getting the same "unexpected value 'stages'" in the editor until I indented the rest of the yaml.

Although this may not directly answer the original poster's issue, it does answer the title of this issue and this issue was the first one I selected when I was searching.

Upvotes: 0

Leo Liu
Leo Liu

Reputation: 76996

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.

Upvotes: 2

Related Questions