Getting git commit labels similar to [skip ci] as env variables
O
Originaldavz
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
T
Timothy Clarke
This one looks like it should be a bash or similar script to parse then commit message and then do
echo "MY_ENV_VAR=${VALUE_FROM_COMMIT}" >> ${BASH_ENV}
in a - run
step prior to the NPM commandM
Mohamed
I have tried to use the same here as u explained
I added this values in my environment_Variables for the project then tried to use with the circleci paramaters but didn't work
and when im sshing inside the ci machine im trying to echo it , it doesn't evaluate to the message i need
it evaluates to this main string that i put in the env variable
any advice ?
Liya Ai
Mohamed: Hi Mohamed - if you need some help troubleshooting please submit a ticket with our support team: https://support.circleci.com/hc/en-us/requests/new