Context:
I have two YAML Build Definitions in the same Azure DevOps Git repo. The YAML files are sitting on separate folders component1 and component2, the build triggers are filtered based on the path. Here are the YAML files:
First file in folder component1:
name: 1.0$(Rev:.rr)
trigger:
branches:
include:
- master
- release/*
paths:
include:
- component1
resources:
- repo: self
steps:
- task: CopyFiles@2
displayName: My Copy Step
inputs:
SourceFolder: 'component1'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
Second file in folder component2:
name: 1.0$(Rev:.rr)
trigger:
branches:
include:
- master
- release/*
paths:
include:
- component2
resources:
- repo: self
steps:
- task: CopyFiles@2
displayName: My Copy Step
inputs:
SourceFolder: 'component2'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
I also have a Release pipeline that is triggered by both artifacts and deploy the latest of these both artifacts.
My goal:
What I want to achieve is when the release is automatically created, I want to filter the artifacts so that the release uses the latest artifacts that originated from the "triggering" branch.
So if I put it in a sequence, it would be like this:
- I change a file in
component1in themasterbranch. - The
component1build definition kicks in and creates the artifact based on themasterbranch. - The release pipeline is triggered due to the creation of the artifact in step 2, and the artifacts used for this release is the latest versions that originated from the
masterbranch, for both artifacts
Then I do the following sequence:
- I change a file in
component2in thereleasebranch. - The
component2build definition kicks in and creates the artifact based on thereleasebranch. - The release pipeline is triggered due to the creation of the artifact in step 2, and the artifacts used for this release is the latest versions that originated from the
releasebranch. NOT the latest from the previous sequence, for both artifacts.
Problem/Question:
It seems that there is no option so far to choose the source branch dynamically. I tried to use the $(Release.Artifacts.{Artifact alias}.SourceBranchName) variable for the "Default version" field, but that would not trigger the release.
Is my goal doable? And if yes, how?

