Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure-DevOps: Automatic increment docker tag in Azure Pipeline

steps:
- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: myAcrServiceConnection
    repository: roket
    tags: |
      02
      latest

The above snippet build an image with tag 02 and tag latest from the same source and push it to the azure container registry.

How can I replace the 02 in the tags to an automatic increment style. For example it will fist fetch the remote or local catch and increment 1 to the tag?

like image 808
SLN Avatar asked Oct 25 '25 22:10

SLN


1 Answers

You can define the build number in a way that is going to strictly increment (for instance $(Date:yyyyMMdd)$(Rev:.rr)), and use $(Build.BuildNumber) as a tag for the image.

From the official documentation:

Use $(Rev:r) to ensure that every completed build has a unique name. When a build is completed, if nothing else in the build number has changed, the Rev integer value is incremented by one.

like image 101
Lucas Avatar answered Oct 27 '25 23:10

Lucas