Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tagging a Docker image with Version in Gitlab with yaml

I'm currently digging in Gitlab CI. I would like to add a way in my YAML files to tag my docker images generated by the build step and pushed to my Gitlab Registry with a Version number composed in the following fashion : MajorVersion.Minorversion.BuildNumber

I would like to auto-increment the BuildNumber, but to manually set the MajorVersion and MinorVersion.

I found a standard variable CI_JOB_ID for the build ID. But i need a smooth way to manage my version numbers..

like image 726
Aurelien Avatar asked Jul 04 '18 09:07

Aurelien


2 Answers

Not a 100% solutions for you but we are using TAGs for this purpose.

Part of gitlab-ci.yml

 - docker build --pull -t $CI_REGISTRY/releases/application:$CI_COMMIT_TAG .
 - docker push $CI_REGISTRY/releases/application:$CI_COMMIT_TAG

So every time we push a new tag, a new docker image with release number is build. You can limit those steps in .gitlab-ci.yml via:

  only:
    - tags
    - /^my-release-.*$/

Now only tags with "my-release-x.x.x" are pushed.

like image 105
opHASnoNAME Avatar answered Nov 01 '22 21:11

opHASnoNAME


So i did it by adding a CI_VERSION variable in my script :

variables:
  CI_VERSION: "1.0.${CI_JOB_ID}"

build-master:
  stage: build
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" -t "$CI_REGISTRY_IMAGE:$CI_VERSION"   ./postfix
    - docker push "$CI_REGISTRY_IMAGE"
  only:
    - master

And it works fine, now i need to find a way to keep the ten (for example) last build.

like image 43
Aurelien Avatar answered Nov 01 '22 20:11

Aurelien