Filter VSTS Build Artifiacts for release based at "triggering" branch

Viewed 264

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.

enter image description here

enter image description here

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:

  1. I change a file in component1 in the master branch.
  2. The component1 build definition kicks in and creates the artifact based on the master branch.
  3. 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 master branch, for both artifacts

Then I do the following sequence:

  1. I change a file in component2 in the release branch.
  2. The component2 build definition kicks in and creates the artifact based on the release branch.
  3. 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 release branch. 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?

0 Answers
Related