I had a deployment script which I wanted to control by passing an argument (major, minor or patch)
Circle CI already has a way to skip builds by using [skip ci] in a commit message so it seems like a good place to pass messages/commands to the CI.
First thing, get the correct git commit message ($CIRCLE_SHA1 is provided by CircleCI):
GIT_COMMIT_MSG=
git log --format=oneline -n 1 $CIRCLE_SHA1
Next, find the label that you are interested in:
CI_COMMIT_LABEL=
[[ "$GIT_COMMIT_MSG" =~ ^.*\[(major|minor|patch)\ ci\]|\[ci\ (major|minor|patch)\].*$ ]] && echo ${BASH_REMATCH[1]}${BASH_REMATCH[2]}
This regex simply finds the ci label inside square brackets exactly like the skip command. It works as
[ci minor]
or
[minor ci]
I'm no regex expert but this works for me and can probably be improved by somebody.
Finally, pass the label on to my script:
npm run make-release $CI_COMMIT_LABEL
This lets me easily tell Circle CI a label what sort of release I want whenever I commit/merge to master, the default inside my make-release script is patch though so I only need to pass minor or major when I know I need to. Hope this helps somebody
CCI-I-1024