Automation of releases with gitlab CI
Oct 6, 2020
Intro
Task
Automatically set release tag and release metadata when code (release candidate) gets into a master branch.
Preconditions
- Development takes place in dev branch
- bump2version used for managing tags
- Tags, used while developing: X.Y.Z-rcN
Needed flow:
- Developer add code to dev branch and make bumpversion with -rcX tag
- Developer create merge request (MR) from dev to master branch
- After code gets into master branch the CI job will create release (X.Y.Z) tag, and release with description (for example: random generated codename of release)
Solution
1. Gitlab service account
Create gitlab service account and access token (personal access token also can be used for testing purposes):
- Create service user: Admin area → Overview → Users → Newuser.
- Set following parameters:
name: bot-service-account
username: bot-service-account
email: bot-service-account@mail.com
access level: regular
external: true - Go to created user profile (bot-service-account →Impersonation Tokens), and create “impersonation token” with read_repository and write_repository permissions.
- Add BOT_TOKEN env variable (Settings →CI/CD →Variables) to gitlab project.
- Add BOT_NAME and BOT_EMAIL vars with gitlab username and email accordingly.
- Uncheck the protected box for created CI variables if you want variable be accesed from other branches
2. Pipeline
Next we need to create pipeline with ability to set tags.
In gitlab preoject create .gitlab-ci.yml file:
3. Version managing
To manage git tags we use bumpversion with following configuration:
bumpversion.cfg :
Source
Gitlab repo with sources: https://gitlab.com/fl64/autotag