I have an Azure DevOps pipeline that references two repos:
- The code repo, which contains my application code
- The config repo, which contains my environment variable config files.
The idea is that I should be able to make simple config changes and re-deploy without changing the application's version number (since the code hasn't changed). However, I still want to be able to see in the version number that the config changed between runs.
As a result, I'm thinking of using a version number in the following format:
{major}.{minor}.{codeVersion}.{configVersion}
... with the following constraints:
{major}and{minor}are to be set manually by the developer.{codeVersion}should auto-increment every time there is a commit to the code repo as long as{major}.{minor}hasn't changed.{configVersion}should auto-increment every time there is a commit to the config repo as long as{major}.{minor}.{codeVersion}hasn't changed.
Note: I understand that running the pipeline twice in quick succession would result in the same version number for both runs. This is acceptable since there were no changes to either repo in between.
As an example, I might expect to see a bunch of pipeline runs with the following names:
MyApp 0.1.0.0Initial pipeline runMyApp 0.1.1.0Change to application codeMyApp 0.1.1.1Change to environment configMyApp 0.1.2.0Change to application codeMyApp 0.1.2.0No change to code nor config- ...
I've had a look at the counter function, but it doesn't seem to do what I need. My first attempt was this:
name: '$(Build.DefinitionName)-$(major).$(minor).$(codeVersion).$(configVersion)'
variables:
- major: 0
- minor: 1
- codeVersion: $[counter(format('{0}.{1}', variables['major'], variables['minor']), 0)]
- configVersion: $[counter(format('{0}.{1}.{2}', variables['major'], variables['minor'], variables['codeVersion']), 0)]
Unfortunately, with this code the codeVersion value always changed on every run even if I made no commits to the code repo. Then, as a result, the configVersion value was always zero.
I've tried a few variations of the above where I tried referencing the $(Build.SourceVersion) variable to get the git commit ID but I haven't been able to find a working solution yet.
The fundamental issue seems to be that the counter function increments when the supplied values haven't changed, whereas I want it to increment when the commit ID of the code repo has changed.
Edit: Fixed typo

