[英]Azure Data Factory CI/CD - automatic publish after merge to master branch
[英]CI/CD pipelines Azure devops automatic merge after deploy release
我有一個經典的環境。 設置如下:
我有 2 個分支: Develop
和Master
。
Azure DevOps 中是否有任何方法可以設置以下規則:
在開發環境中部署成功時(在 azure devops 的發布管道中定義) ------>自動創建pull request
以將開發合並到Master中。
或另一個:如果開發分支的Build
成功------->自動創建pull request
以將開發合並到 Master 。
任何幫助將不勝感激。
我剛剛上傳了執行此操作的擴展程序: https : //marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk.CreatePullRequest
您可以使用Azure DevOps Rest API創建請求請求,因此在Build / Release的最后添加執行此任務的PowerShell任務,例如:
$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
您需要允許腳本訪問OAuth令牌(選中“代理作業”選項中的復選框):
結果:
我將基本參數放在正文中(從分支到分支,標題),但是您可以添加更多參數,例如評論者,請在此處檢查文檔。
使用 python 和devops rest api人們已經提到你可以做這樣的事情。
# Tested in python 3.10
# pip install requests
import base64
import requests
# Fill the following variables with real values
personal_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxx' # https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&viewFallbackFrom=vsts&tabs=Windows
organization = "myorganization"
project_id = "00000000-0000-0000-0000-000000000000"
repository_id = "00000000-0000-0000-0000-000000000000"
authorization = str(base64.b64encode(bytes(f":{personal_access_token}", "ascii")), "ascii")
headers = {"Content-type": "application/json", "Authorization": f"Basic {authorization}"}
prs_url = f"https://dev.azure.com/{organization}/{project_id}/_apis/git/repositories/{repository_id}/pullrequests?api-version=5.1"
# create PR
response = requests.post(
f"{prs_url}",
headers=headers,
data=json.dumps({
"sourceRefName": "refs/heads/release",
"targetRefName": "refs/heads/master",
"title": "release to master",
}),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.