MichaSchumann MichaSchumann - 1 year ago 149
Git Question

Gitlab runner conditional run depending on commit message

I have been using Gitlab for a while and now set up a build server. As I change machines (Notebook/PC) I often commit and push to save my work to my gitlab server as the contents are regulary backed up to the cloud.

The build server, works great but the complete project is build on every push. As its quite a big one, I would like to do something like this:

  • Push commits with comment "release" - > Gitlab triggers the

  • All other pushes of commits are ignored by the runner.

It is ok if only the head commit comment ist checked on build.

I searched the .gitlab.yml documentation but could not find anything helpful.

Answer Source

Based on your example message "release", the best approach is to restrict the build to tagged commits only.

In your exinsting gitlab-ci.yml file, add the "only" attribute to the end of the step you want to restrict.

  stage: build
- echo "building..."
# - Your commands here
- tags

Now, every time you need to build it, just tag the commit using:

git tag "release"

If you really need to see every commit the message you should look in the CI Variables, there's a way to get the current commit hash ref.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download