5

I'd like to set a dash plus the repo tag to a Docker image build if the build is a build of a tag, and neither if it is not, I'll explain...

This would be trivial if I just wanted to set the tag if it existed because this would work:

build-nginx:
  stage: build-nginx
  script:
    - command docker build -t $CI_REGISTRY_IMAGE:nginx$CI_COMMIT_TAG .
    - command docker push $CI_REGISTRY_IMAGE:nginx$CI_COMMIT_TAG

This could create registry.example.com/image:nginx if there was no tag and registry.example.com/image:nginx1.0 if there was, but how would I get the image to be named registry.example.com/image:nginx-1.0 (with a dash), I've have to check if the tag variable was set otherwise I'd end up with and image called registry.example.com/image:nginx- if the tag variable was not set.

1
  • I have solved this for now by splitting and duplicating my stages and using "only: - tags". Commented Apr 7, 2017 at 8:50

1 Answer 1

6

Normally I do something like

- if [ -z "$CI_COMMIT_TAG" ]; then docker build -t $CI_REGISTRY_IMAGE:nginx$CI_COMMIT_TAG .; else docker push $CI_REGISTRY_IMAGE:nginx-$CI_COMMIT_TAG; fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.