Read commit message as a CIRCLE environment variable



I have a project requirement to run certain test cases only on master builds. This is done by a unittest decorator like this @unitttest.skipUnless(os.environ['CIRCLE_BRANCH'] == "master", "Run test cases only on master builds")
I also want this to run these test cases if a developer chooses to run it on any non-master branch.

I’m wondering if there is a way to override the unittest decorator with a git command(git commit/push) so that the test cases gets picked up and executed in Circle CI. Perhaps an environment variable which could read the PR label from github or the commit message ? Something like “[ci skip]” - But instead of skipping, which can be read as an environment variable within the CI environment ?


Yes, you can use following command to read the commit message and set it as environment variable.

GIT_COMMIT_DESC: git log --format=oneline -n 1 $CIRCLE_SHA1

Note: $CIRCLE_SHA1 is a predefined circleci environment variable.