Marc
Marc

Reputation: 14269

Pass Build Version to Release

How does one pass the build version (say v1.2.3) from an Azure DevOps Build Pipeline to/through the Artifact to the Release? Ideally we would like our build number (in package.json) to match the release name or rather our release name should reflect the build number/semantic version.

A manual solution where we enter the version number when creating the release is also acceptable. The release has a Release Name format which is set to Parts-$(Build.Buildnumber). We can see no way to use custom values (entered at release creation) here. The documentation is unclear on how to use these variables.

enter image description here

Upvotes: 1

Views: 2119

Answers (2)

Eric Swiggum
Eric Swiggum

Reputation: 107

In your yml file declare a variable like so,

variables:
 DBCR: $[replace(variables['build.sourceversionmessage'], '/', '-')]

after which you can create a custom build number in your yaml like so,

name: $(DBCR)_v$(Rev:r)

and then use $(Build.Buildnumber) in your release pipelines "Release name format".

Simple and effective :)

Upvotes: 0

Marc
Marc

Reputation: 14269

OK, I discovered the answer.

  1. Set the build name dynamically from your build script using the ##vso[] directive as follows (in our case by readining version from package.json:
$ver = (Get-Content -Raw ./package.json | ConvertFrom-Json).version
Write-Host "##vso[build.updatebuildnumber]$ver"
  1. Use $(Build.Buildnumber) in your release pipelines "Release name format".

Upvotes: 3

Related Questions