Automation of releases with gitlab CI

Pavel Tishkov
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)
Needed flow scheme

Solution

1. Gitlab service account

Create gitlab service account and access token (personal access token also can be used for testing purposes):

  1. Create service user: Admin area → Overview → Users → Newuser.
  2. Set following parameters:
    name: bot-service-account
    username: bot-service-account
    email: bot-service-account@mail.com
    access level: regular
    external: true
  3. Go to created user profile (bot-service-account →Impersonation Tokens), and create “impersonation token” with read_repository and write_repository permissions.
  4. Add BOT_TOKEN env variable (Settings →CI/CD →Variables) to gitlab project.
  5. Add BOT_NAME and BOT_EMAIL vars with gitlab username and email accordingly.
  6. 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

--

--

Responses (1)