CI/CD管道部署发布后,Azure devops自动合并
我有一个经典的环境.设置如下:
I have a classic env. setup like following:
我有2个分支:Develop
和Master
.
Azure DevOps中是否可以设置以下规则:
Is there any way in Azure DevOps to setup the following rule:
-
在开发环境中成功部署时(在 ------> 创建自动将 develop 合并为 Master 的
pull request
.
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.
或另一个:如果 develop分支的Build
成功,则 ------->
自动创建 以将开发合并为Master .
or the other one: if a Build
of develop branch is succeded ------->
create automatically a pull request
to merge develop into Master.
任何帮助将不胜感激.
我刚刚上传了一个扩展程序,可以这样做: https://marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk.CreatePullRequest
您可以使用 Azure DevOps Rest API 创建一个Pull请求,因此在Build/Release的最后添加一个执行此任务的PowerShell任务,例如:
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
您需要允许脚本访问OAuth令牌(选中代理作业"选项中的复选框):
You need to Allow scripts to access the OAuth token (check the checbox in the Agent Job options):
结果:
我将基本参数放在正文中(从分支到分支,标题),但是您可以添加更多参数,例如审阅者,检查文档
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.