成功发布后触发发布

问题描述 投票:0回答:1

我的场景:

我在azure devops中获得了几个发布管道,每个管道都部署了自己的应用程序。现在这些应用程序互相使用api:s。因此,在部署完成后,他们会运行系统测试。因此,每个发布管道都有一个共享任务组,其管道中包含系统测试。通常,部署成功,但有时系统测试不会,因此即使部署完成,整个版本也将失败。这让我很烦。

现在,我想将此系统测试移至其自己的发布管道,并在部署完成时触发。这可能吗?

azure-devops
1个回答
1
投票

您可以在第一个发布作业结束时添加Azure PowerShell任务。因此,当第一个发布作业完成时,它会触发第二个发布作业。只需传递第二个作业定义ID即可。

电源外壳 :

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 !!!"
}
© www.soinside.com 2019 - 2024. All rights reserved.