Customise build pipelines using tags on merge request.
Problem to solve
Customise build pipelines using tags on merge request.
Further details
We are currently using a webhook bot that decorates our titles with the labels using [label1][label2] etc. This allows us to customise our pipelines quite freely. But is flaky to say the least. Adding an environment variable that populates this from the merge request would allow a lot more flexibility when to run tests, when to deploy or not, and to wish environments, as well as selecting what to bump tag like.
Here is an example how we bump versions today using the CI_COMMIT_MESSAGE and a webhook bot, but would like for it to be part of the information for the master pipeline:
#
# Template for tagging, Takes a variable for BUMP_MODE that can be patch, minor, major or hotfix.
#
.git-tag: &git-tag
stage: release
except:
refs:
- tags
variables:
- $CI_COMMIT_MESSAGE =~ /\[silent-ignore\]/
- $CI_COMMIT_MESSAGE =~ /\[maven-release-plugin\]/
before_script:
- git-create-settings
- eval $(ssh-agent -s)
- git remote set-url origin git@gitlab.com:${CI_PROJECT_PATH}.git
- export OLD_TAG=$(git-latest-tag)
- export NEW_TAG=$(git-semver -i ${BUMP_MODE} ${OLD_TAG})
script:
- git tag ${NEW_TAG}
- git push origin ${NEW_TAG}
#
# Will create a tag for the hotfix pipeline. This will be based on latest semver with a number and hash added to it.
#
git-tag:hotfix:
<<: *git-tag
variables:
BUMP_MODE: "hotfix"
only:
refs:
- master
variables:
- $CI_COMMIT_MESSAGE =~ /\[hotfix\]/
#
# Will create a major release tag.
#
git-tag:major:
<<: *git-tag
variables:
BUMP_MODE: "major"
only:
refs:
- master
variables:
- $CI_COMMIT_MESSAGE =~ /\[major\]/
#
# Will create a minor release tag.
#
git-tag:minor:
<<: *git-tag
variables:
BUMP_MODE: "minor"
only:
refs:
- master
variables:
- $CI_COMMIT_MESSAGE =~ /\[minor\]/
#
# Will create a patch release tag. This is the default tagging.
#
git-tag:patch:
<<: *git-tag
variables:
BUMP_MODE: "patch"
only:
- master
except:
variables:
- $CI_COMMIT_MESSAGE =~ /\[hotfix\]/
- $CI_COMMIT_MESSAGE =~ /\[major\]/
- $CI_COMMIT_MESSAGE =~ /\[minor\]/
The hotfix is a way for us to get a merge request out to production in minimum available steps (skip test, skip deploy to stage etc..). This is usually done command line by those who knows how. But with this feature we can give this flexibility to all developers.
Giving this in a new variable would allow us to ditch the webhook solution as the information is present in the master pipeline as tags from the latest merge request. And we don't need to rely on the webhook to be up and running all the time.
Proposal
Provide a CI_COMMIT_LABELS with the labels added from the merge request that was merged latest. This will create possibility to build up the pipeline depending on the review process. For example you can bump major / minor version instead of patch for each master build.
only:
refs:
- master
variables:
- $CI_COMMIT_LABELS =~ /\[bump:major\]/
What does success look like, and how can we measure that?
Fully customisable pipelines using the review tool.
Links / references