2

I'm using the counter function in Azure Pipelines to generate the version patch, allowing me to get an autoincremented version number as part of my CI/CD.

version.major: 4
version.minor: 2
version.patch: $[counter(format('{0}.{1}', variables['version.major'], variables['version.minor']), 0)]
version.full: $[format('{0}.{1}.{2}', variables['version.major'], variables['version.minor'], variables['version.patch'])]

However, I now need this version counter to be shared between two pipelines in the same repository. One of the pipelines publishes some packages, whilst the other deploys some resources. I'd like the pipelines to be separate since sometimes one would need to be run without the other – for example, because they're triggered for different path filters. However, I would like them both to contribute to the same versioning sequence – I don't want my packages to have version numbers disparate from the resources.

Is there a way of achieving this shared versioning sequence? I've already tried variable reuse, but the counter gets evaluated in the outer pipeline, not the inner template where it's defined.

14207973
  • 489
  • 6
  • 19

1 Answers1

0

What you need is passing variables from one pipeline to another. I'm afraid it can not be achieved by default.

As a workaround you could create a variable group. Then every time there is a new version number in first pipeline, update the value of the variables inside your variable group. Then in second pipeline use the variables in the variable group.

There are multiple ways to update variable group, Rest API, powershell, 3rd-party extension. Detail ways please refer answers in this question: How to Increase/Update Variable Group value using Azure Devops Build Definition?

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39