提问人:Gustavo Vargas 提问时间:11/4/2023 更新时间:11/8/2023 访问量:38
如何在分支的Azure DevOps分支策略上创建生成验证?
How can I create Build Validations on Azure DevOps branch policies for forks?
问:
我在 Azure DevOps 上有 2 个存储库,第二个存储库是作为第一个存储库的分支创建的。我的团队希望从原始存储库的分支到分支上的主分支创建 PR,或者使用分支上的源分支和目标分支创建 PR。
如何在分支策略上创建生成验证,以从 PR 生成源分支,具体取决于它是来自原始存储库还是来自分支?使用单个生成验证不起作用,因为生成管道仅面向其中一个存储库。
任何帮助将不胜感激。
谢谢!
答:
从你的描述中,
如何在分支策略上创建生成验证,以从 PR 生成源分支,具体取决于它是来自原始存储库还是来自分支?
如果要在两个存储库上从 PR 生成源分支,可以创建两个生成验证,一个用于原始存储库,另一个用于分叉存储库。然后签出 yaml 管道中的多个存储库。
您可以按照以下步骤操作:
1.添加两个构建验证。(一个用于原始回购,另一个用于分叉回购)
2 签出多个存储库。
resources:
repositories:
- repository: seocond
type: git
name: "your second repo name"
steps:
- checkout: self
- checkout: seocond
当从原始存储库或 fork 存储库创建新 PR 或将更改推送到面向分支的现有 PR 时,将触发生成。
如果有任何误解,请提供与您的问题相关的更多信息。
如何在分支策略上创建生成验证,以从 PR 生成源分支,具体取决于它是来自原始存储库还是来自分支?
可以检查 的预定义变量值,并在生成验证管道中确定生成哪个源分支。您可以指定运行任务的条件。$(System.PullRequest.IsFork)
$(System.PullRequest.SourceRepositoryURI)
$(System.PullRequest.SourceBranch)
如果创建了 PR 或 ,则 System.PullRequest.IsFork 值将为 true。并将显示源存储库 URL。将显示没有 repo 信息的源分支。from original repo to fork
from fork to original
System.PullRequest.SourceRepositoryURI
System.PullRequest.SourceBranch
例如,我有原始的 repo test1,其中包含分支 main 和 dev,并创建了一个 fork repo。我创建了从原始 repo dev1 到民间 repo 主分支的 PR:
我创建了一个从分叉的 repo dev1 到分叉的主分支的新 PR:
我在下面构建验证示例,为任务添加条件,以便在从原始 repo dev1 创建 pr 到分叉的 repo 主分支时执行它。
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'))
上一个:如何在管道中添加分支列表选择参数
下一个:Git rebase 空分支
评论