0

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!!

Thomas
  • 35
  • 2
  • 8
  • 1) May be a slightly different question. Why can't you add a task to directly invoke the tests in the build pipeline itself at the end. 2) Moreover, Did you try checking the option `triggers` ? – rootkonda Jan 28 '21 at 09:07
  • Very sorry, I am pretty new to azure devops could explain how its really done please? – Thomas Jan 28 '21 at 09:20

1 Answers1

1

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

Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31