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

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

问题描述

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

I have a classic env. setup like following:

我有2个分支:DevelopMaster.

Azure DevOps中是否可以设置以下规则:

Is there any way in Azure DevOps to setup the following rule:

  1. 在开发环境中成功部署时(在 ------> 创建自动将 develop 合并为 Master pull request.

  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.

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

这篇关于CI/CD管道部署发布后,Azure devops自动合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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