Skip build at GitLab CI


After installing GitLab with GitLab CI I was like "wow, this is really awesome, my own GitHub and own Travis.. Great". But then I found out that sometimes I'll need option to skip some builds, just like Travis has.

So I read one article somewhere, unfortunately I don't remember where and there the author described one method, how to have different build steps for each branch.

The idea is that you have got your build script directly in your project (eg. gitlab_ci file) and at your CI setup just this one line:

$ /bin/bash ./gitlab_ci

And I think that that's great, because the build logic can now be more complex. And if you have this build file in your project, adding "skip" option is not so difficult.

# get commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)


# see if commit message contains "[skip ci]" string
if [[ ${COMMIT_MESSAGE} == *\[skip\ ci\]* ]]; then
    echo "Skipping ci build"
    exit 0
fi

So now, you can just add [skip ci] to your commit message, and next build will be skipped.

Well, of course it will not be truly skipped, just exited shortly... Also in list of builds, you will see that this build passed. So when I really need to use that skip option, I just add [skip ci] string to the beginning of commit message, so it will be at least somehow visible.

Builds