Azure Devops构建管道-意外的价值阶段

时间:2020-03-24 08:48:39

标签: azure-devops yaml build-pipeline

我正在重构使用阶段作为模板的管道,因此在测试发布构建管道和发布构建管道中没有重复的代码。但是我收到了在以下.yml行中注释的错误。

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

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

我检查了文档,但看不到任何错误。你能指出我的错误以及我应该改变什么吗?

1 个答案:

答案 0 :(得分:1)

Azure Devops构建管道-意外的价值阶段

该错误可能来自模板。由于模板直接嵌套在舞台下,因此您应该确保模板也在舞台下

类似于以下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!"

然后 build-job.yml

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

它对我来说很好,您可以检查是否对您有用。

此外,如果您设置模板直接嵌套在步骤下,则模板应以步骤开始。

如果您不满意,请在问题中分享详细的构建错误日志。

希望这会有所帮助。

相关问题