AzD Passing Artifact Path Name to Release

AzD Passing Artifact Path Name to Release

November 2, 2019 0 By Morten Lerudjordet

On the path to make something generic, one task is to make as much as possible be variable based. By that I mean one place to define a value as a variable, then use it throughout the pipeline by referencing saied variable . This is good practise because it will make it more robust for reuse, and are good first steps on the journey towards a more holistic approach towards treating pipeline config as code.

One such need I have found, is that there is no robust way in the release pipeline task to reference a file inside the artifact build produces.

Hardcoding the value seems trivial at first, though once pipelines become complex. Changing anything with hardcoded values will break the pipeline in unpredictable ways.

One way of making this a bit more robust is to use the built in Release.PrimaryArtifactSourceAlias variable. This will be populated at agent runtime with the name of the primary artifact. So if one uses multiple artifacts, one of these must be set as primary for this to work as expected. So it has some downside, though with careful thought one can make it work.

This looks better, though we still have to input the artifact name.

One way to solve this is to build on my previous post about how to pass information between Build and Release.

So if we take the evolved build yaml from that post:

Here I have added a new variable called ArtifactName, this is then populated with the value one wants to use.

The next change is to the PublishBuildArtifacts task, where one instead of naming the artifact directly there. Instead reference it through the variable name ‘$(ArtifactName)’.

Now we will need to get this information over to the Release pipeline.
This is where we build upon the last post, where we in the AzP-Helpers.ps1 script add an input parameter called ArtifactRootPathName. Here we pass inn the same variable used to name the artifact.

Now inside the script:

Note where the variable is added:

Be aware that the shared variable ArtifactRootPathName must be first created before first time use.

Finally we can change out the static path in the release pipeline with runtime logic like this.

Congratulation on one tiny step on the road to a more generic and robust pipeline.

Happy tinkering!