Creating a Docker image in Bamboo using Docker task throws "invalid reference format" exception
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
This article talks about the problem seen while creating the Docker image in Bamboo using Docker task and assigning a tag to it. The tag can be either derived using Bamboo variable, branch name, etc or defined manually.
The Docker task while creating the image fails with exception ERROR: invalid tag "" : invalid reference format.
Environment
Issue was seen on Bamboo 9.2.4 but the solution will be applicable for all supported versions of Bamboo.
Diagnosis
To diagnose the problem please refer the Viewing a build log and we can see the below error when the docker task fails
1
2
ERROR: invalid tag "releaseBranchTestingVersion1" : invalid reference format.
Last command executed with error! Exit code 1, message: None
Here we are trying to define a tag "releaseBranchTestingVersion1" to the Docker image which is being created ( Please note that this tag contains both lowercase and uppercase letters )
Cause
If we read the Docker tag convention page, it mentions not to use uppercase letters in the Docker tag name.
"The path consists consists of slash-separated components. Each component may contain lowercase letters, digits and separators. A separator is defined as a period, one or two underscores, or one or more hyphens. A component may not start or end with a separator. While the OCI Distribution Specificationopen_in_new supports more than two slash-separated components, most registries only support two slash-separated components."
The problem can occur if any of the above rules are violated with the tag name.
Solution
The current problem was related to using both lowercase and uppercase in the Docker tag, the solution is to just use the lowercase.
As explained earlier tag can be either a branch name, variable name or something manually defined, below are some example on how to convert them from uppercase to lowercase
1
2
echo ${bamboo.planKey} | tr '[:upper:]' '[:lower:]'
echo ${bamboo.planRepository.branch} | tr '[:upper:]' '[:lower:]'
Before
1
2
build 02-Nov-2023 12:17:41 SCRIP-TIC2
build 02-Nov-2023 12:17:41 TESTING_bamboo_BITBUCKET
After
1
2
build 02-Nov-2023 11:50:29 scrip-tic2
build 02-Nov-2023 11:50:29 testing_bamboo_bitbucket
Was this helpful?