CI/CD 管道 Azure devops 在部署发布后自动合并 [英] CI/CD pipelines Azure devops automatic merge after deploy release

查看:22
本文介绍了CI/CD 管道 Azure devops 在部署发布后自动合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经典的环境.设置如下:

我有 2 个分支:DevelopMaster.

Azure DevOps 中是否有任何方法可以设置以下规则:

  1. 在开发环境(定义在azure devops 的发布管道)------> 自动创建一个 pull requestdevelop 合并到 Master>.

  2. 或另一个:如果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:

  1. 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.

  2. or the other one: if a Build of develop branch is succeded -------> create automatically a pull 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆