CI/CD pipelines Azure devops automatic merge after deploy release
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.
Comments
-
Haithem KAROUI almost 2 years
I have a classic env. setup like following:
I have 2 branches:
Develop
andMaster
.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.
-
Haithem KAROUI almost 5 yearsThank you for your answer, can please provide more details about this : "you can script this yourself using the oauth token, or using your own auth to issue a request against the api." thanks
-
4c74356b41 almost 5 yearsI've been doing this with github, you just need to call the api for merge: developer.github.com/v3/repos/merging
-
Dicky Moore over 4 yearsIf you receive the "You need the Git 'PullRequestContribute' permission to perform this action" error upon running the script in a release pipeline, who do you grant these permissions to?
-
Shayki Abramczyk over 4 years@DickyMoore To the build service account, did you get the error even you enable the "Allow scripts to access....."?
-
Mohamad Mousheimish over 3 yearsAs mentioned in the documentation, you can add a reviewer with the following:
"reviewers": [{"id": "d6245f20-2af8-44f4-9451-8107cb2767db"}
How can I get the Id of the user I want to add as reviewer?? -
Shayki Abramczyk over 3 years@MohamadMousheimish you can check the code of my extension that mentions above, there are different ways, check there.
-
MANZARBEITIA over 2 yearsReceiving this error with @ShaykiAbramczyk extension > "message":"TF401179: An active pull request for the source and target branch already exists."
-
Shayki Abramczyk over 2 years@MANZARBEITIA it means that there is already PR open...
-
MANZARBEITIA over 2 years@ShaykiAbramczyk this issue only happened using YAML, when I used the classic editor it worked as expected.
-
Shayki Abramczyk over 2 years@MANZARBEITIA and the settings are the same? please open an issue in my GitHub github.com/shayki5/azure-devops-create-pr-task/issues