I’m using CircleCI for periodic builds (3 a week), and it works great.
Except when there’s a issue and need to issue a fix. Since my CircleCI only triggers based on schedule, pushing the fix upstream doesn’t initiate a build.
If I manually choose ‘Rerun workflow’ from the dashboard, CircleCI unfortunately reuses the old commit (and not the most recent one).
So I likely need a job that triggers based on some condition. I thought about inspecting the commit message (as discussed here on the forum in other threads, like here). But I’m hopelessly stuck making that work.
If I don’t a .circleci.yml
approach, let me know since that’s the quickest approach.
Here’s what I tried so far:
Use a bash variable
implement_fix:
docker:
- image: cibuilds/hugo:0.54.0
steps:
- checkout
- run:
name: Check if commit includes [fix]
command: |
CMT=git log --format=oneline -n 1 $CIRCLE_SHA1
echo $CMT
Output:
CMT=git log --format=oneline -n 1 $CIRCLE_SHA1
echo $CMT
/bin/bash: log: command not found
Exited with code 127
Perhaps a quoted variable?
implement_fix:
docker:
- image: cibuilds/hugo:0.52
steps:
- checkout
- run:
name: Check if commit includes [fix]
command: |
CMT="git log --format=oneline -n 1 $CIRCLE_SHA1"
echo $CMT
echo $CMT
git log --format=oneline -n 1 381a054044c20bbfb475087d547d089497fccd39
Using bash export, following the docs
https://circleci.com/docs/2.0/env-vars/
implement_fix:
docker:
- image: cibuilds/hugo:0.54.0
steps:
- checkout
- run:
name: Check if commit includes [fix]
command: |
echo 'export CMT_MSG=git log --format=oneline -n 1 $CIRCLE_SHA1' >> $BASH_ENV
- run:
name: 'Commit message is:'
command: echo $CMT_MSG
Woops, neither works:
/tmp/.bash_env--0-build: line 1: export: `--format=oneline': not a valid identifier
/tmp/.bash_env--0-build: line 1: export: `-n': not a valid identifier
/tmp/.bash_env--0-build: line 1: export: `1': not a valid identifier
/tmp/.bash_env--0-build: line 1: export: `6db97969c361b9858c028a57bd41507c8adedcd3': not a valid identifier
git
Using an environment variable, following this thread
implement_fix:
docker:
- image: cibuilds/hugo:0.54.0
environment:
- GIT_COMMIT_DESC: git log --format=oneline -n 1 $CIRCLE_SHA1
steps:
- checkout
- run:
name: 'Commit message is:'
command: echo $GIT_COMMIT_DESC
Output:
echo $GIT_COMMIT_DESC
git log --format=oneline -n 1 $CIRCLE_SHA1
Use when
command, from the docs
https://circleci.com/docs/2.0/configuration-reference/#the-when-attribute
implement_fix:
docker:
- image: cibuilds/hugo:0.54.0
environment:
GIT_COMMIT_DESC: $(git log --format=oneline -n 1 $CIRCLE_SHA1)
steps:
- checkout
- run:
name: "Set environment variable"
command: echo $GIT_COMMIT_DESC
- when:
condition:
steps:
- run:
name: "Successful match of condition"
command: echo "Success!"
Doesn’t work for me; output is the following instead of the actual commit message:
$(git log --format=oneline -n 1 $CIRCLE_SHA1)