首页 > 解决方案 > 更改多阶段管道中 1 阶段的存储库

问题描述

我有一个 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. 所以问题是,我可以为特定阶段更改此存储库吗?

标签: azureazure-devopsazure-pipelinesmultistage-pipeline

解决方案


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

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

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


推荐阅读