Reference the Commits of Build Artifacts in Azure Pipelines

Viewed 270

I have an Azure Pipeline which

  • is triggered manually
  • downloads the build artifacts of 3 other pipelines, all of them based on different (git) repositories
  • allows the user to input the BuildId (Run number) of these pipeline-artifacts, to choose which runs to take them from
  • creates a package with them
  • is written in YAML

I'm looking for a way to show in the "Source Code" tab the Source code link for the commit relative to each of pipeline builds, which artifacts have been downloaded during this run. To do this, I have to name each of the repositories and checkout the proper version.

What I can't get my head around is how to exploit the BuildId variable to get the SourceVersion variable.

I know that Build.BuildId variable is the one defining the run id of the pipeline, and we use this to choose which run to take the specific artifact from. At the same time, Build.SourceVersion contains the commit Id used for the pipeline run. But normally, Build is the current Build.

How can I reference Build_x, starting from Build_x.BuildId, so to be able to recover the Build_x.SourceVersion?

Thank you

1 Answers

Based on your requirement, I suggest that you can change use the Pipelines Resource in YAML pipeline.

Here is an example:

resources:
  pipelines:
  - pipeline: PipelineAlisa
    project: project
    source: Pipelinename

  - pipeline: PipelineAlisa
    project: proejct
    source: Pipelinename

pool:
  vmImage: windows-latest

steps:
- download: MyCIAlias
- download: MyCIAlias1

In this case, you can still select the Build runs when your run the pipeline(Resources option).

enter image description here

This should also be able to achieve the same function as your existing pipeline.

And this method can more conveniently obtain the corresponding build id and source version of pipeline artifacts.

You can directly use the variables:

Source version : RESOURCES.PIPELINE.Aliasname.SOURCECOMMIT

Build ID: RESOURCES.PIPELINE.Aliasname.RUNID

For example:

enter image description here

Related