7

I am going to create my CI/CD pipeline in Azure DevOps, but I have a problem with release version number. with this CI/CD a dotnet app build and a docker image created, so I want to have docker image release number same as : V1.2.0 and ..... but currently I have number for example: 10, 11, ... or only the latest tag! Can anybody support me to have my own release version number ? Thanks

Meraj Kashi
  • 283
  • 1
  • 8
  • 18
  • 2
    https://learn.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops#how-do-i-manage-the-names-for-new-releases – Shayki Abramczyk Jul 13 '20 at 13:26
  • You can use our SaaS solution to keep control of versions - be it semver, calver or something custom; it integrates with any CI/CD platform - https://worklifenotes.com/2020/02/27/automatic-version-increments-with-reliza-hub-2-strategies/ – taleodor Jul 15 '20 at 03:32

2 Answers2

19

You could set the release version number in Release Pipelines -> Options -> General -> Release name format.

enter image description here

The $(rev:r) is an incrementing variable. So you could add it in the Release version.

For example: V1.2.$(rev:r)

Result:

enter image description here

Note: the $(rev:r) counts from 1 (1,2,3...).

From your requirement, you are using CI and CD process and it seems that you need to count from 0. You also could try to use the $(Build.buildnumber) variable.

Here are the steps:

Step1: In Build Pipeline(CI) , set the count variable(e.g. BuildRevision :$[counter( ' ',0)]).

enter image description here

Step2: Use the variable in Build number (Build Pipeline->Options ->Build number format).

enter image description here

Step3: Set the build artifacts as the release source. Use the $(Build.buildnumber) in release pipeline version.

enter image description here

Result:

enter image description here

In this situation, the release version could start from v1.2.0.

Update:

when I change the release version for example from V0.0 to V1.0 , how the counter restarted ?

You could try the following steps:

Create 2 variables:

1.major-minor = 0.0

2.revision = $[ counter(variables['major-minor'],0) ]

The build number: $(major-minor).$(revision)

In this case, when the major-minor change as V1.0, the counter will reset.

enter image description here

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Thanks, What I did is : defining 2 variables : BuildRevision:V0.0 and BuildRevisionCounter : $[counter(' ',0)], so it works properly. My question is, when I change the release version for example from V0.0 to V1.0 , how the counter restarted ? – Meraj Kashi Jul 24 '20 at 10:27
  • 1
    Hi @MerajKashi. Please check the update. When you change the variable , the counter will restart. – Kevin Lu-MSFT Jul 27 '20 at 00:58
  • I wish I could find this great idea 3 years ago, before creating Release Pipelines for specific public facing DLLs just because I needed release numbers integrated into the assemblies. – Alexander Sep 20 '21 at 09:21
  • Really like the idea ! For people in need: We intended to use GitVersion but the build pipeline failed constantly after adding it to our project >> wheras variables in pipeline works perfectly – Azutanguy Mar 18 '23 at 08:54
1

In that case you can use GitVersion and Semantic Versioning pattern. For that you will need this extension: https://marketplace.visualstudio.com/items?itemName=gittools.gitversion

After that you add the step before compiling/build your project:

steps:
 - task: GitVersion@5
   inputs:
      runtime: 'core'

After that you can use variable:

$(GitVersion.FullSemVer)

That variable will store the current build version - it's based on git.