MichaSchumann MichaSchumann - 9 days ago 7
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 1.2.3.4" - > Gitlab triggers the
    build

  • 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

Based on your example message "release 1.2.3.4", 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.

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

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

git tag "release 1.2.3.4"

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.

Comments