sen*_*sen 7 azure azure-devops
在 Azure devops 发布管道中,我试图在两个不同的阶段之后运行一个阶段,如下所示。我在运行 API 测试阶段时遇到问题。
预期的:
如果 Dev 或 QA 阶段成功,则需要运行 API 测试。
实际的:
开发阶段成功时不会触发 API 测试阶段。
请让我知道所需的配置。
除了重复 API 测试阶段之外,另一个解决方法是使用Update Release Environment rest api。请参阅以下步骤:
1、设置API-Test阶段仅在Dev阶段后自动触发。
设置管理部署以允许帐户yourProjectname Build Service(Your Organization)。此权限将允许您更新发布管道中的发布环境。
3、进入QA阶段-->在代理作业部分-->检查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
Run Code Online (Sandbox Code Playgroud)
上述脚本首先调用get Release Rest api来获取 API-Test 阶段的环境 ID。然后调用更新发布环境rest api触发部署到API-Test。
这样上面的脚本就可以实现手动部署到QA阶段成功后触发API-Test阶段。
归档时间: |
|
查看次数: |
396 次 |
最近记录: |