From 2d65ae1fb77471245c1074ee5909c8bbf0b0e6b9 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Thu, 1 Jul 2021 12:56:28 +0200 Subject: [PATCH] CI/CD: add alternative version tag --- .gitlab-ci.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01e18b8..7e6273a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,19 +35,27 @@ build-docker-image: # This job runs in the build stage, which runs first. -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + - export VERSION="$(echo + "${CI_COMMIT_BRANCH}_$(date +%Y%m%dT%H%M%S)_${CI_COMMIT_SHA:0:8}" + |sed 's,/,--,g')" # Default branch leaves tag empty (= latest tag) # All other branches are tagged with the escaped branch name (commit ref slug) script: - | - if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then + if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then tag="" echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" else tag=":$CI_COMMIT_REF_SLUG" echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" fi - - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" . + - docker build + --pull + --file Docker + --tag "$CI_REGISTRY_IMAGE${tag}" . + --tag "$CI_REGISTRY_IMAGE:$VERSION" . - docker push "$CI_REGISTRY_IMAGE${tag}" + - docker push "$CI_REGISTRY_IMAGE:$VERSION" # Run this job in a branch where a Dockerfile exists rules: - if: $CI_COMMIT_BRANCH