3
votes

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?

2

2 Answers

1
votes

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

9
votes

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]