我的场景:
我在azure devop中有几个发布管道,每个管道都部署自己的应用程序。现在这些应用程序互相使用api:s。因此,完成部署后,他们将运行系统测试。因此,每个发布管道都有一个共享的任务组,在它们的管道中具有系统测试。通常,部署成功,但是有时系统测试无法完成,因此即使完成部署,整个发行版也会失败。哪个让我烦。
现在,我想将此系统测试移至其自己的发布管道,并且在完成部署后将触发它。这可能吗?
答案 0 :(得分:1)
您可以在第一个发行作业的末尾添加Azure PowerShell任务。这样,当第一个发布作业完成时,它将触发第二个发布作业。只需传递第二个工作定义ID。
PowerShell:
Param(
[string]$vstsAccount = "software",
[string]$projectName = "project",
[string]$definitionId = "895",
[string]$keepForever = "true",
[string]$personalAccessToken = "xxxxxx"
)
# Base64-encodes the Personal Access Token (PAT)
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) }
# Construct the REST URL
$uri = "https://vsrm.dev.azure.com/$vstsAccount/$projectName/_apis/release/releases?api-version=5.0-preview.8"
Write-Host "Uri :" $uri
$params =
@"
{
"definitionId": $definitionId,
"description": "Create Release from PowerShell Script",
"artifacts": [],
"isDraft": false,
"reason": "VSTS Trigger",
"manualEnvironments": null,
"environmentsMetadata": null,
"properties": null,
"variables": null
}
"@
Write-Host "Request Body :" $params
# Invoke the REST call and capture the results
$result = Invoke-RestMethod -Uri $uri -Method POST -Body $params -Headers $headers -ContentType "application/json" -Verbose -Debug
Write-Host "Result :" $result
# This call should only provide a single result
if ($result.count -eq 0)
{
Write-host "Unable to locate Release Definition Id $definitionId"
}
else
{
Write-host "Successfully triggered the VSTS release job !!!"
}