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..
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.
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.
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