[英]How to execute next stage in Azure Devops Release pipeline?
除了復制 API-Test 階段之外,另一個解決方法是使用Update Release Environment rest api 。 請參見以下步驟:
1、設置API-Test階段僅在Dev階段后自動觸發。
設置管理部署以允許帳戶yourProjectname Build Service(Your Organization) 。 此權限將允許您更新發布管道中的發布環境。
3、Go到QA階段-->在Agent job部分-->勾選Allow scripts to access the OAuth token
。 此設置將允許您在發布管道中使用訪問令牌。
4、經過以上准備,現在可以在QA階段的最后添加一個腳本任務來調用發布rest api。 請參閱 powershell 任務中的以下示例:
#Get releaseresponse
$Releaseurl= "https://vsrm.dev.azure.com/{yourOrg}/$(System.TeamProject)/_apis/Release/releases/$(Release.ReleaseId)?api-version=6.0-preview.8"
$releaseresponse = Invoke-RestMethod -Method Get -Headers @{Authorization = "Bearer $(system.accesstoken)"} -ContentType application/json -Uri $Releaseurl
#Get the environment ID of API-Test stage from the release response:
$id = $releaseresponse.environments | Where-Object{$_.name -match "API-Test"} | select id
#Create the JSON body for the deployment:
$deploymentbody = @"
{"status": "inprogress"}
"@
#Invoke the REST method to trigger the deployment to API-Test stage:
$DeployUrl = "https://vsrm.dev.azure.com/{yourOrg}/$(System.TeamProject)/_apis/release/releases/$(Release.ReleaseId)/environments/$($id.id)?api-version=6.0-preview.7"
$DeployRelease = Invoke-RestMethod -Method Patch -ContentType application/json -Uri $DeployUrl -Headers @{Authorization = "Bearer $(system.accesstoken)"} -Body $deploymentbody
上述腳本首先調用get Release rest api獲取 API-Test 階段的環境 id。 然后調用更新發布環境rest api觸發部署到API-Test。
這樣上面的腳本就可以實現手動部署到QA階段成功后觸發API-Test階段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.