在Azure DevOps中完成发布后,如何创建请求请求?

Saw*_*oes 3 git pull-request azure-devops azure-pipelines azure-pipelines-release-pipeline

我正在从事的项目有2个长期存在的功能分支以及master分支。

为了完全自动化部署,每当部署从Azure DevOps版本中退出时,我想创建一个从master到这两个功能分支的提取请求。

Azure DevOps中的哪种工具将允许我将发布请求创建为发布任务?

sta*_*SFT 9

您可以在发行期间通过Pull Request REST API创建Pull Request 。

这里有调用HTTP REST API的任务,但可能无法满足您的要求。

简单的方法是您可以通过PowerShell任务来执行此操作

  1. 选择阶段(例如,在代理上运行),然后选中“ 允许脚本访问OAuth令牌”选项。您也可以使用个人访问令牌
  2. 添加PowerShell任务

简单样本:

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
Run Code Online (Sandbox Code Playgroud)

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