Azure Pipelines手动CI构建中如何指定多仓库分支?
解决Azure Pipelines手动构建指定TESTS仓库分支的问题
方法1:通过运行时参数手动指定分支
在YAML开头定义一个可配置的参数,手动触发构建时直接输入或选择TESTS仓库的目标分支:
parameters: - name: testsBranch type: string default: master displayName: TESTS仓库分支 resources: repositories: - repository: APPLICATION type: git name: AAA/APPLICATION ref: master - repository: TESTS type: git name: AAA/TESTS ref: ${{ parameters.testsBranch }} # 绑定参数 stages: - stage : BuildApplication # checkout分支及构建步骤 - stage : BuildTests # checkout分支及构建步骤
手动触发构建时,页面会显示TESTS仓库分支的输入框,填入目标分支名即可,默认值为master。
方法2:用管道变量覆盖固定分支
先将TESTS仓库的ref绑定到管道变量,再在手动构建时覆盖变量值:
resources: repositories: - repository: APPLICATION type: git name: AAA/APPLICATION ref: master - repository: TESTS type: git name: AAA/TESTS ref: $(TestsBranch) # 绑定管道变量 stages: - stage : BuildApplication # 构建步骤 - stage : BuildTests # 构建步骤
- 进入管道的「变量」设置,添加名为
TestsBranch的变量,默认值设为master; - 手动触发构建时,在「变量」选项卡中修改
TestsBranch的值为目标分支名即可。
方法3:关联APPLICATION分支(分支名一致场景)
如果APPLICATION和TESTS仓库的分支名完全对应(比如都使用feature/xxx这类命名),可以直接让TESTS仓库拉取与当前APPLICATION分支同名的分支:
resources: repositories: - repository: APPLICATION type: git name: AAA/APPLICATION ref: $(Build.SourceBranchName) # 自动使用触发构建的分支 - repository: TESTS type: git name: AAA/TESTS ref: $(Build.SourceBranchName) stages: - stage : BuildApplication # 构建步骤 - stage : BuildTests # 构建步骤
这样手动选择APPLICATION的某个分支时,TESTS仓库会自动检出同名分支。
内容的提问来源于stack exchange,提问作者Coder
相关产品推荐
相关产品推荐

