I’ve looked on the docs and forum for this, but is there a way to get the git commit message in an environment variable, like you can get the $CIRCLE_SHA1? I want to use this in a deployment script to AWS Elastic Beanstalk with the aws elasticbeanstalk create-application-version command to give the new application version a meaningful description.
Hey thanks for the quick response, I didn’t realise you could do that sort of thing.
But I did try this and I can’t get it to work, the command format is right. I chose to use --format=oneline. But I can’t get it to actually return a value.
It just seems to return “git”, i guess not executing it. I’ve tried also enclosing it in $() (which just makes it blank) and also using the UI for env vars but still no luck.
Bit of a newbie with all this so apologies for any stupidity.
Update: for completeness I should say I’m then passing this env var to a script like in this circlei documentation:
thanks - just updated my answer with some more details. also yeah i tried at first the environment under the command as you had it, but was getting syntax errors. thanks again!
yeah all the deployment itself to EB works and all the downstream stuff is fine without me trying to get the git message, so I’ll just play around with doing it at different points and post back here. thanks for all the help
‘deployment.productionshould’ be a either a deploy section with commands, a Heroku deploy section or a CodeDeploy deploy section.
have got it working from within the shell script itself (not surprisingly) so that’s good enough for me at the moment and i’ll see if any other thoughts come to mind and post back if so
I don’t know how to get how many commits there have been since the previous build, but you can set how many commits to return in your arguments to git log by changing the ‘1’ to how many you want to see. For example, git log --format=oneline -n 5 $CIRCLE_SHA1 would print the last five commits (if your number is greater than the number of commits to a repo, it doesn’t break–it just prints as many as you have).
You can also do more with the format. For example, git log --format="%s" -n 5 $CIRCLE_SHA1 would print just the commit messages without the hash.
See https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History.