Archimedes Trajano
Archimedes Trajano

Reputation: 41740

How do I create a "copy" of a build with the number from another project pipeline

Because of the limitation of Azure Test Plans not being able to choose a build from a different project, I was wondering if it is possible to create a pipeline that would at least clone the build number from another project.

Here's the narrative:

There's a project ProjA with pipeline P1 that generates a build number using the following line

name: $(date:yyyyMMdd)$(rev:.r)

I want it such that:

Another project ProjB has a pipeline P1 which matches the name in ProjA gets triggered so that there's a build recorded whenever ProjA.P1 is successful and have the build recorded with the same name as the build run from ProjA.P1

UPDATE note I am looking specifically for ProjA.P1 and not whatever would've triggered ProjA.P1. The original accepted answer works for the simple case where ProjA.P1 is triggered from the ProjA.P1 pipeline.

However, if ProjA.P1 has triggers: none and uses resources.pipelines to trigger it's build it uses the build number of the referenced pipeline rather than ProjA.P1.

Upvotes: 1

Views: 679

Answers (1)

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30442

We can set a pipeline completion trigger to Trigger one pipeline after another. (ProjB.P1 is triggered when ProjA.P1 completes.)

We can get the trigger build name using the resource variable $(resources.pipeline.<Alias>.runName) in YAML. (It will retrieve the buildNumber of the pipeline ProjA.P1 in pipeline.) See Pipeline resource metadata as predefined variables for details.

Then using the UpdateBuildNumber logging command (##vso[build.updatebuildnumber]build number) to update the build number of the ProjB.P1.

ProjB.P1 YAML for your reference:

trigger: none

resources:
  pipelines:
  - pipeline: ProjA-Trigger  # Any alias here
    source: P1               # The real pipeline name (ProjA.P1 here)
    project: ProjA           # Project ProjA
    trigger:
      branches:
        include:
          - refs/heads/main

steps:
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: 'echo "##vso[build.updatebuildnumber]$(resources.pipeline.ProjA-Trigger.runName)"'

Upvotes: 2

Related Questions