Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tagging docker image with tag from git repository

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

like image 981
Noel Avatar asked Jul 19 '18 21:07

Noel


People also ask

How do I tag a docker image?

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.

How do I map a custom tag for an image in Docker?

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.

How do I tag a docker image as latest?

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 .


1 Answers

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

like image 157
Sascha Frinken Avatar answered Oct 11 '22 02:10

Sascha Frinken