[英]How to trigger a build from another build pipeline in azure devops
I have two build pipeline for two different projects.One is for building the actual project and another build pipeline for test automation.我有两个用于两个不同项目的构建管道。一个用于构建实际项目,另一个构建管道用于测试自动化。 I want to automatically trigger the build pipeline of test automation once the actual project build succeed.
一旦实际项目构建成功,我想自动触发测试自动化的构建管道。
does there any possible way can i add one more task down to the actual build to trigger the test automation build, or suggest a possible way for the same.有什么可能的方法我可以在实际构建中添加一个任务来触发测试自动化构建,或者建议一种可能的方法。
Answers are much appreciable!!答案非常可观!!
You can use the "Build Completion" trigger in your second pipeline:您可以在第二个管道中使用“构建完成”触发器:
Additionally, you can add PowerShell script to queue another build from the parent build.此外,您可以添加 PowerShell 脚本以将来自父构建的另一个构建排队。 Example:
例子:
$user = ""
$token = $env:SYSTEM_ACCESSTOKEN
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "$env:SYSTEM_COLLECTIONURI"
$teamProject = "$env:SYSTEM_TEAMPROJECT"
$buildBodyTemplate = "{`"definition`": {`"id`": <build_id>}}"
$restApiQueueBuild = "$orgUrl/$teamProject/_apis/build/builds?api-version=6.0"
function InvokePostRequest ($PostUrl, $body)
{
return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body
}
function RunBuild($buildId)
{
$buildBody = $buildBodyTemplate.Replace("<build_id>", $buildId)
Write-Host $buildBody
$buildresponse = InvokePostRequest $restApiQueueBuild $buildBody
Write-Host $buildresponse
}
RunBuild SECOND_BUILD_ID
Update SECOND_BUILD_ID
to ID of your build definition with tests.使用测试将
SECOND_BUILD_ID
更新为构建定义的 ID。 Additionally, add access to the security token in the parent build:此外,在父构建中添加对安全令牌的访问:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.