CI/CD 管道 Azure devops 在部署发布后自动合并 [英] CI/CD pipelines Azure devops automatic merge after deploy release
问题描述
我有一个经典的环境.设置如下:
我有 2 个分支:Develop
和 Master
.
Azure DevOps 中是否有任何方法可以设置以下规则:
在开发环境(定义在azure devops 的发布管道)------> 自动创建一个
pull request
将 develop 合并到 Master>.或另一个:如果develop分支的
Build
成功------->创建自动一个pull request
以合并develop到Master.
任何帮助将不胜感激.
我刚刚上传了一个扩展程序:
您需要允许脚本访问 OAuth 令牌(选中代理作业选项中的复选框):
结果:
我将基本参数放在正文中(从分支、到分支、标题),但您可以添加更多参数,例如审阅者,请查看文档 这里.
I have a classic env. setup like following:
I have 2 branches: Develop
and Master
.
Is there any way in Azure DevOps to setup the following rule:
When a deploy is succeeded on dev environment (defined in the release pipeline of azure devops) ------> create automatically a
pull request
to merge develop into Master.or the other one: if a
Build
of develop branch is succeded -------> create automatically apull request
to merge develop into Master.
Any help will be appreciated.
Edit:
I just uploaded an extension that does it: https://marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk.CreatePullRequest
You can use Azure DevOps Rest API to create a Pull Request, so in the end of the Build / Release add a PowerShell task that do it, for example:
$body = @{
sourceRefName= "$(Build.SourceBranch)"
targetRefName = "refs/heads/master"
title = "PR from Pipeline"
}
$head = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$json = ConvertTo-Json $body
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullrequests?api-version=5.0"
Invoke-RestMethod -Uri $url -Method Post -Headers $head -Body $json -ContentType application/json
You need to Allow scripts to access the OAuth token (check the checbox in the Agent Job options):
Results:
I put the basic parameters in the body (from branch, to branch, title) but you can add more parameters like reviewers, check the docs here.
这篇关于CI/CD 管道 Azure devops 在部署发布后自动合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!