I am using Gitlab for repository and ci/cd. Currently trying to set up pipeline that creates a docker image from a build stage. All examples I have seen have a simple naming of image where e.g. the branch is used(master)
My question is if I want to tag the image based on the current tag in the repository how do I do this? I am presuming I can use a Gitlab runner variable but do not see one to us
A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
You can pull a Docker Image using the pull sub-command. You can specify the tag of the Image that you want to pull. Note that if you don't specify a tag, it will automatically pull the latest version of the Image by appending the “latest” tag to the Image.
Latest is Just a Tag It's just the tag which is applied to an image by default which does not have a tag. Those two commands will both result in a new image being created and tagged as :latest: # those two are the same: $ docker build -t company/image_name . $ docker build -t company/image_name:latest .
There are a lot of predefined variables in Gitlab CI. I think you are looking for CI_COMMIT_TAG
.
So you could use it this way:
docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
So the image would look like registry.example.com/group/project:tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With