在多阶段管道中更改 1 阶段的回购

Change repo for 1 stage in multi-stage pipeline

我有一个 azure devops 多阶段管道,需要 1 个阶段将文件从另一个存储库复制到 $(build.artifactstagingdirectory)

例如我的 YAML 看起来像

trigger: 
  - master

resources:
  - repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:
  - job: Build
 ...
- stage: Build
  ... define other resource/repository ...
  - task: CopyFiles@2
    inputs:
      SourceFolder: 'k8s'
      Contents: '**'
      TargetFolder: '$(build.artifactstagingdirectory)'

此管道连接到可能由 repo: self 定义的存储库。所以问题是,我可以为特定阶段更改此存储库吗?

您可以在 powershell 脚本中 运行 git 命令。在您的阶段中添加一个步骤来执行 git 命令,如下例所示。这样,其他仓库将被克隆到工件目录。

- powershell: |
      cd $(Build.artifactstagingdirectory)
      git clone "https://<<Your PAT>>@dev.azure.com/_organization/_project/_git/_repo"

注意:使用您的个人访问令牌 (PAT) 作为身份验证。