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

て烟熏妆下的殇ゞ 提交于 2019-12-04 04:21:00

问题


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?


回答1:


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:




回答2:


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]



来源:https://stackoverflow.com/questions/48634358/how-can-i-create-a-pull-request-when-a-release-completes-in-azure-devops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!