1
votes

I want the Azure DevOps pipeline below to automatically trigger when both resource pipelines successfully has built the same commit of master. Is this possible? Right now it triggers when one of the pipelines is finished resulting in two runs.

trigger: none
pr: none

resources:
  pipelines:
    - pipeline: "buildPipeline1"
      source: "BuildPipeline1"
      trigger:
        branches:
        - master

    - pipeline: "buildPipeline2"
      source: "BuildPipeline2"
      trigger:
        branches:
        - master
2

2 Answers

1
votes

Now this is not possible. Your pipeline will fire in case of any of defined trigger pass. So if you need sth like this you need to build using webhooks. You can for instance call Azure Function when your pipeline succeeded. Keep there a track in some database or other form of state that pipeline A was run for commit 32563456 and then when Pipeline B will run for the same commit and your function is being notified you will trigger this pipeline from Azure Function.

I know that this sound like plenty of work but this is not supported to have out of the box.

1
votes

Sorry, it's not possible for now.

For pipeline triggers, we could only trigger a pipeline upon the completion of another, specify the triggering pipeline as a pipeline resource.

You could refer our official doc here-- Trigger one pipeline after another

The only workaround I could come across, add a task in the end of your two pipelines, query the other pipeline's status if the same commit built and built succeed.

Finally we can add task power shell and add script to call the REST API to queue the build/any other pipeline based on previous task result.

$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$PipelineUrl = "https://dev.azure.com/{Org name}/{project name}/_apis/pipelines/{Pipeline ID}/runs?api-version=6.0-preview.1" 

$body ="{ 
 `"resources`":{
        `"repositories`":{
            `"self`":{`"refName`":`"refs/heads/master`"
            }
         }
    }
}"
$Pipelines = Invoke-RestMethod -Uri $PipelineUrl -ContentType "application/json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST