Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CI/CD pipelines Azure devops automatic merge after deploy release

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.

like image 241
Haithem KAROUI Avatar asked May 17 '19 10:05

Haithem KAROUI


People also ask

How do I link a release pipeline in Azure DevOps?

Select Releases under Pipelines section. The Azure DevOps project created a release pipeline to manage deployments to Azure. Select the release pipeline, then choose Edit. Under Artifacts, select Drop.


1 Answers

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

Photo3

You need to Allow scripts to access the OAuth token (check the checbox in the Agent Job options):

Photo1

Results:

enter image description here

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.

like image 182
Shayki Abramczyk Avatar answered Oct 20 '22 22:10

Shayki Abramczyk