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

Azure Devops Build Pipeline - Unexpected value stages

我正在重构管道以使用阶段作为模板,因此我的测试发布构建管道和发布构建管道中没有重复代码。但是我收到了我在以下 .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

我对照文档进行了检查,但没有发现任何问题。你能指出我的错误和我应该改变的地方吗?

Azure Devops Build Pipeline - Unexpected value stages

错误可能来自模板。由于模板是直接嵌套在舞台下的,所以你应该确保模板也在舞台下

喜欢下面的 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'

我这边很好用,你可以检查一下它是否适合你。

另外,如果你设置模板直接嵌套在steps下,那么模板应该以steps开头。

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

希望对您有所帮助。