Often when you’re working with build and release pipelines, you want to use variables from the build pipeline in your release. Today I was asked by a co-worker how you can find the build number from a build artifact and use that in one of the tasks in a release.
The answer can be found in the use of what are called Primary artifact variables. You designate one of the artifacts as a primary artifact in a release pipeline. For the designated primary artifact, Release Management populates a number of variables. For my co-worker, he was interested in the Build number so after designating the primary artifact, he could use the Build number in a task in his release using the following syntax.
Release.Artifacts.{Primary artifact alias}.BuildNumber
The primary artifact is generally the artifact you select initially when you create your release initially.
Here’s a screenshot showing how to use the build variable in a task in your release pipeline. I’m choosing to use a Command Task to output the Build number in the logs just to keep the demonstration easy to follow.
There are quite a few more primary artifact variables you can use. Check out the Microsoft docs for a complete list.