问题
I have a classic env. setup like following:
I have 2 branches: Develop
and Master
.
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.
回答1:
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.
回答2:
- there is no build-in tasks for that, but you can script this yourself using the oauth token, or using your own auth to issue a request against the api.
- pretty much the same approach can be used here, or you can use Branch policies to force pull requests to be validated before merging them to master (which in my mind is better, because merging from develop to master on every commit is pretty pointless).
来源:https://stackoverflow.com/questions/56184170/ci-cd-pipelines-azure-devops-automatic-merge-after-deploy-release