Skipping a CI Build for non-code changes

Table Of Contents

Skipping a CI build is like purposefully not brushing your teeth every morning and evening. You know it should not be skipped and you feel guilty when you do it anyways. However, there are some cases when you have only changed some supplementary files (like documentation) that have no impact whatsoever on your build pipeline and you don’t want to wait for a long-running build. Here are two ways how to skip a CI build in this case.

Using the Commit Message [skip ci]

The easiest way to skip a CI build is to add [skip ci] or [ci skip] to your commit message. Many CI providers support this:

This solution has two major drawbacks, though.

Firstly, it pollutes the git commit messages with meta information that is only relevant to the CI system and brings no value to the commit history.

Secondly, the above commit message will cause the CI system to ignore the push / pull request completely, i.e. it will not even register in your CI history. This will cause any hooks you have installed to your build pipeline not to run.

You’re screwed, for example, if you have protected the branches of your GitHub repository, so that pull requests can only be merged when the CI build for the pull request has successfully run. This will never happen using [skip ci], so you can never merge the pull request… .

Using a Git Diff in the CI Build

So, we actually want the CI build to start - only to immediately exit when only non-code changes were made.

I’ve found a nice script for Travis CI on GitHub and modified it a little:

if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(.md$)'
then
  echo "Only docs were updated, not running the CI."
  exit
fi

This script creates a diff of all commits within the $TRAVIS_COMMIT_RANGE (i.e. within the current push or pull request) and exits the build if it only includes markdown files (*.md). We could modify the regular expression to include more than just markdown files. It can be included into a build, like I did in my code examples repository.

However, of the big CI providers, only Travis CI currently supports the necessary “commit range” environment variable:

A Word of Caution

Use wisely and with caution. The build should never be skipped when a file changed that has any impact on the build. So, if your markdown files are part of your build, don’t skip the build.

Written By:

Tom Hombergs

Written By:

Tom Hombergs

As a professional software engineer, consultant, architect, general problem solver, I've been practicing the software craft for more than fifteen years and I'm still learning something new every day. I love sharing the things I learned, so you (and future me) can get a head start. That's why I founded reflectoring.io.

Recent Posts

Guide to JUnit 5 Functional Interfaces

In this article, we will get familiar with JUnit 5 functional interfaces. JUnit 5 significantly advanced from its predecessors. Features like functional interfaces can greatly simplify our work once we grasp their functionality.

Read more

Getting Started with Spring Security and JWT

Spring Security provides a comprehensive set of security features for Java applications, covering authentication, authorization, session management, and protection against common security threats such as CSRF (Cross-Site Request Forgery).

Read more

Creating and Publishing an NPM Package with Automated Versioning and Deployment

In this step-by-step guide, we’ll create, publish, and manage an NPM package using TypeScript for better code readability and scalability. We’ll write test cases with Jest and automate our NPM package versioning and publishing process using Changesets and GitHub Actions.

Read more