首页 > 解决方案 > 带有模板的 azure devops yaml 管道不签出引用的存储库

问题描述

我正在使用新的 Azure DevOps Yaml 多阶段管道功能

我有一个要使用模板的 Azure DevOps yaml 管道文件。我希望管道可以检出自己和另一个存储库。

出于某种原因,运行时已检出self repo,但 repo: pipelines 未检出,因此作业失败(因为它所需的某些文件依赖项不存在。

这是我的模板的摘录:

resources:
  repositories:
  - repository: self
  - repository: pipelines
    name: vstsproject/pipelines
    type: git
    source: pipelines

variables:
  # Container registry service connection established during pipeline creation
  imageRepository: 'vstsprojectweb'
  dockerfilePath: '$(Build.SourcesDirectory)/src/Dockerfile.CI'
  BuildConfiguration: 'Release'
  tag: '$(Build.BuildId)'  

stages:

- stage: 'PRD'
  jobs:
  - template: update-connection-string-db.yml@pipelines
    parameters:
      resourceGroup: 'application-DEV'
      DBSearchString: '###dbservername###'  

我做错了什么?

我已经参考了这个微软文档

标签: azure-devopsazure-pipelines

解决方案


您不需要在资源(即 self)中引用链接的 repo,如果它是唯一的 repo,则默认情况下会在作业(而不是部署作业)中签出,但如果您有其他 repo,那么您需要手动检查它们(使用 -checkout: <name_of_repo>)。

所以就这样做(PS:清理一下,假设回购在同一个项目中):

resources:
  repositories:
  - repository: pipelines
    source: pipelines

variables:
  # Container registry service connection established during pipeline creation
  imageRepository: 'vstsprojectweb'
  dockerfilePath: '$(Build.SourcesDirectory)/src/Dockerfile.CI'
  BuildConfiguration: 'Release'
  tag: '$(Build.BuildId)'  

stages:

- stage: 'PRD'
  jobs:
  - checkout: self
  - checkout: pipelines
  - template: update-connection-string-db.yml@pipelines
    parameters:
      resourceGroup: 'application-DEV'
      DBSearchString: '###dbservername###'  

推荐阅读