How to automatically increment the version of a Docker image built with Bamboo

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.

You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.

We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!

When using Bamboo to build Docker images, it can be useful to auto-increment the version tag. This article covers a way to do this.

Environment

Bamboo with Docker tasks, specifically the Build a Docker Image one.

Solution

You can use Bamboo's build number variable (or any other suitable Bamboo variables) in the Repository field as the image's tag. For example, the following configuration can be implemented:

  1. Build a Docker image task configuration

    registry.address:port/namespace/repository:tag.${bamboo.buildNumber}

    (Auto-migrated image: description temporarily unavailable)
  2. Additionally, if you also use a Dockerpush task, it also accepts variables in the Repository field:

    namespace/repository:tag.${bamboo.buildNumber}

    (Auto-migrated image: description temporarily unavailable)

The build logs show that the image was built using the Bamboo Build Number as part of the tag:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 command 18-May-2022 21:15:01 Substituting variable: ${bamboo.buildNumber} with 7 [...] Docker Build simple 18-May-2022 21:15:03 Built Docker image 'registry.address:port/namespace/repository:tag.:1.1.7' simple 18-May-2022 21:15:03 Finished task 'Docker build' with result: Success [...] Docker Push build 18-May-2022 21:15:08 The push refers to repository [registry.address:port/namespace/repository] build 18-May-2022 21:15:08 4fc242d58285: Preparing build 18-May-2022 21:15:12 4fc242d58285: Mounted from library/alpine build 18-May-2022 21:15:18 1.1.7: digest: sha256:... size: 527 command 18-May-2022 21:15:18 Beginning to execute external process for build '2022 - Docker push image - Default Job #7 (TTT-DPI-JOB1-7)'\n ... running command line: \n/usr/local/bin/docker logout\n ... in: /bamboo-agent-home/xml-data/build-dir/TTT-DPI-JOB1\n build 18-May-2022 21:15:18 Removing login credentials for https://index.docker.io/v1/ simple 18-May-2022 21:15:18 Finished task 'Docker push' with result: Success

And the Image gets pushed successfully to the registry:

(Auto-migrated image: description temporarily unavailable)

Additionally, you might be looking for a way to automate the update of the Global Variable value as well. This won't be as straightforward as the steps above, but it's possible to do so by enabling a "dark feature" in Bamboo. Bamboo has an API for Global variables, which can list, add, update, and remove Global variables. This API is hidden by default, which means that it needs to be enabled, and also comes with limited support.

This feature can be enabled through the steps described in this article.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.