Running circle config validation as pre-commit hook in git

When you work on the CircleCI pipeline you have to edit mainly the .circleci/config.yml file. To avoid pushing errors to the repository, you can use the circleci-cli tool to validate the CircleCI configuration file. To make this a little bit easier you can run it automatically as a pre-commit hook. Check out the OpenNMS source repository and create in the repository directory the file .git/hooks/pre-commit with the following content:

#!/usr/bin/env bash

# The following line is needed by the CircleCI Local Build Tool (due to Docker interactivity)
exec < /dev/tty

# If validation fails, tell Git to stop and provide error message. Otherwise, continue.
if ! eMSG=$(circleci config validate -c .circleci/config.yml); then
	echo "CircleCI Configuration Failed Validation."
	echo $eMSG
	exit 1

Before git commit the CircleCI tool will verify your config.yml first and if it fails, you can fix it before you make your next commit.