Kevin Ghadyani
Kevin Ghadyani

Reputation: 7297

How can I create a Pull Request when a release completes in Azure DevOps?

A project I'm working on has 2 long-standing feature branches as well as the master branch.

To fully automate deployments, I'd like to create a pull request from master into those two feature branches anytime a deployment goes out from an Azure DevOps Release.

What kind of tooling in Azure DevOps would allow me to do create pull requests as a release task?

Upvotes: 3

Views: 3495

Answers (2)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41555

You can install the Create Pull Request extension, it gives you the ability to create a pull request automatically from your release pipeline with multi target branch:

enter image description here

Upvotes: 1

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

You can create the Pull Request through Pull Request REST API during the release.

There is Invoke HTTP REST API task but may not good for your requirement.

The simple way is that you can do it through PowerShell task:

  1. Select the phase (e.g. Run on agent) and check Allow scripts to access OAuth token option. You can use Personal Access Token too.
  2. Add PowerShell task

Simple sample:

param(
[string]$project,
[string]$repo,
[string]$sourceBranch,
[string]$targetBranch,
[string]$title,
[string]$des,
[string]$token
)
$bodyObj=@{
  "sourceRefName"="refs/heads/$sourceBranch";
  "targetRefName"= "refs/heads/$targetBranch";
  "title"= "$title";
  "description"="$des";
}
$bodyJson=$bodyObj| ConvertTo-Json
$uri="https://XXX.visualstudio.com/DefaultCollection/$project/_apis/git/repositories/$repo/pullRequests?api-version=3.0"
Write-Output $bodyJson
Write-Output $uri
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "test",$token)))
$result= Invoke-RestMethod -Method POST -Uri $Uri -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyJson

Arguments: -project "XXX" -repo "XXX" -sourceBranch "XX" -targetBranch "XX" -title "XX" -des "XX" -token [$(System.AccessToken) or personal access token]

Upvotes: 9

Related Questions