Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

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.

enter image description here

Answers are much appreciable!!

question from:https://stackoverflow.com/questions/65933938/how-to-trigger-a-build-from-another-build-pipeline-in-azure-devops

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the "Build Completion" trigger in your second pipeline:

enter image description here

Additionally, you can add PowerShell script to queue another build from the parent build. 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. Additionally, add access to the security token in the parent build:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...