Can be done with a simple Bash one-liner:
git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s"
Do you want to expose this as an environment variable, so that you can send it to Slack / attach as release notes? Just add a Script step to your workflow (after the git clone step of course ) with the content:
#!/bin/bash
set -ex
# fetch tags, to be sure we have all the require info
git fetch --tags
# collect the commits since the last tag
export GIT_RELEASE_NOTES="$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s")"
# expose as env var for subsequent build steps
envman add --key GIT_RELEASE_NOTES --value "$GIT_RELEASE_NOTES"
After this Script step you can access the generated git release in the $GIT_RELEASE_NOTES
env var, which can be used in other stepsβ input, e.g. in a Slack message or similar.
The generated release note will look something like this (commit hash + first line of the commit message):
4909e29 test output format fix
de07079 release notes test script
8bff3f3 gitignore .bitrise.secrets.yml
Happy Building!
3 Likes
Note: if all you want to get is the last/current git commit message then you can use:
git log -1 --pretty=format:"%h %s"
instead of git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s"
.
Example:
#!/bin/bash
set -ex
# get only the last commit
export GIT_RELEASE_NOTES="$(git log -1 --pretty=format:"%h %s")"
# expose as env var for subsequent build steps
envman add --key GIT_RELEASE_NOTES --value "$GIT_RELEASE_NOTES"
@viktorbenei Thank you for sharing this useful information.
Initially, I was using https://www.bitrise.io/integrations/steps/generate-changelog, but in one case, my commits were missing in the changelog.
Also, I had the same problem with https://www.bitrise.io/integrations/steps/git-commit-changelog.
Case was:
-
bugfix/bug -> commit fix 1 -> push -> tag created -> 1.0.0.100 -> (changelog ok)
-
development -> dev commit 1 -> git push (in this step, no tags have been created)
-
development -> dev commit 2 -> git push (in this step, no tags have been created)
-
bugfix/bug -> commit fix 2 -> push -> tag created -> 1.0.0.101 -> (changelog ok)
-
development -> run bitrise manually -> tag created -> 1.0.0.102 -> (change log is empty)
Iβm not sure if this is expected behavior in these steps I was using initially or its bug.
Thank you
1 Like