I want to add a tag when building a Docker image, I'm doing this so far but I do not know how to get the latest tag on the repository being deployed.
docker build -t company/app .
My goal docker build -t company/app:$LATEST_TAG_IN_REPO? .
gitlab-ci. yml , you can specify some jobs with the tag testing . If a runner with this tag associated is available, it will pickup the job. In Git, within your repository, tags are used to mark a specific commit.
CI_COMMIT_TAG - The commit tag name. Present only when building tags. Therefore in the variables section CI_COMMIT_TAG is not defined, hence equals to "". So if you want to use CI_COMMIT_TAG use in job where tags are defined. See https://docs.gitlab.com/ee/ci/yaml/README.html#tags.
From version 7.12, GitLab CI uses a YAML file ( . gitlab-ci. yml ) for the project configuration. It is placed in the root of your repository and contains definitions of how your project should be built.
Ultimately Codefresh is a DevOps platform designed for containers and Kubernetes. The backbone of all of that is the Codefresh pipelines which provide Docker in Docker as a service.
Since you're looking for the "latest" git tag which is an ancestor of the currently building commit you probably want to use
git describe --tags --abbrev=0
to get it and use it like:
docker build -t company/app:$(git describe --tags --abbrev=0) .
Read here for the finer points on git describe
You can try using $CI_COMMIT_TAG
or $CI_COMMIT_REF_NAME
, this is part of the predefined variables accessible during builds.
If you want to see what are all the available environment variables during build step this should work as one of your jobs:
script:
- env
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