我在 Azure Devops 上有 2 个存储库,第二个存储库是作为第一个存储库的分支创建的。我的团队想要从原始存储库的分支到分叉上的主分支创建 PR,或者使用分叉上的源和目标分支。
如何在我的分支策略上创建构建验证,以从 PR 构建源分支,具体取决于它是来自原始存储库还是来自分叉?进行单个构建验证是行不通的,因为构建管道仅针对其中一个存储库。
任何帮助将不胜感激。
谢谢!
根据您的描述,
如何在我的分支策略上创建构建验证,以从 PR 构建源分支,具体取决于它是来自原始存储库还是来自分叉?
如果您想在两个存储库上从 PR 构建源分支,您可以创建两个构建验证,一个用于原始存储库,另一个用于分支存储库。然后检查 yaml 管道中的多个存储库。
您可以按照以下步骤操作:
1.添加两个构建验证。(一个用于原始存储库,另一个用于分支存储库)
2 查看多个存储库。
resources:
repositories:
- repository: seocond
type: git
name: "your second repo name"
steps:
- checkout: self
- checkout: seocond
当从原始存储库或分支存储库创建新 PR 或将更改推送到针对该分支的现有 PR 时,将触发构建。
如果有任何误解,请提供与您的问题相关的更多信息。
如何在我的分支策略上创建构建验证,以从 PR 构建源分支,具体取决于它是来自原始存储库还是来自分叉?
您可以在构建验证管道中检查 $(System.PullRequest.IsFork)
、
$(System.PullRequest.SourceRepositoryURI)
和 $(System.PullRequest.SourceBranch)
的 预定义变量值,以确定构建哪个源分支。您可以指定 condition 来运行任务。
如果创建 PR
from original repo to fork
或 from fork to original
,则 System.PullRequest.IsFork 值将为 true。和 System.PullRequest.SourceRepositoryURI
将显示源存储库 url。System.PullRequest.SourceBranch
将显示没有存储库信息的源分支。
例如,我有原始存储库 test1,其中包含 main 和 dev 分支,并创建了一个 fork 存储库。我创建了从原始存储库 dev1 到民间存储库主分支的 PR:
我从分叉的 repo dev1 到分叉的主分支创建了一个新的 PR:
我的构建验证示例如下,为任务添加条件,以便当从原始存储库 dev1 到分叉存储库主分支创建 pr 时执行。
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- checkout: none # add checkout none as i don't need to build on the merge branch.
- powershell: |
echo "System.PullRequest.IsFork is: $(System.PullRequest.IsFork)"
echo "System.PullRequest.PullRequestId is: $(System.PullRequest.PullRequestId)"
echo "System.PullRequest.targetBranchName is: $(System.PullRequest.targetBranchName)"
echo "System.PullRequest.SourceBranch is: $(System.PullRequest.SourceBranch)"
echo "System.PullRequest.SourceRepositoryURI is: $(System.PullRequest.SourceRepositoryURI)"
echo "System.PullRequest.TargetBranch is: $(System.PullRequest.TargetBranch)"
continueOnError: true
- powershell: |
echo "This is a sample task when i create from orginal repo dev1 branch to forked repo main branch"
condition: and(eq(variables['System.PullRequest.IsFork'], 'true'), eq(variables['System.PullRequest.SourceBranch'], 'refs/heads/dev1'), endsWith(variables['System.PullRequest.SourceRepositoryURI'], 'test1'))