Bamboo collects Jira issues by commit message, not branch name. Why?

This seems to be intentional. As a result, my developers need to include the issue key in each commit to a feature/hotfix/bugfix branch, and then I must add it AGAIN when I merge their branch into a development trunk.

I've got that "I'm doing it wrong" feeling, but I've found quite a few posts on these forums with the same problem, and this seems like an obvious inefficiency.

Stash is creating my branches, from Jira, and naming them per Stash's naming conventions. I'm surprised that Bamboo cannot map the builds back to the JIRA issues that it addresses, without explicitly noting them in commit messages.

HALP, what am I missing?


EDIT: according to this: the commit message should not be necessary, at least for the linking of plan branches back to JIRA issues.

4 answers

the "prepare-commit-msg" hook needs to be in each developer clone, not on the server.

# check if commit is merge commit
if [ "$2" == "merge" ]; then
ISSUE_KEY=$(git symbolic-ref --short HEAD | sed -n -E 's/.*[/]([A-Z]{2,10}-[0-9]{2,10}).*/\1/p')
if [ "$ISSUE_KEY" == "" ]; then
    # no issue key in branch, use the default message
TPL=$(cat $1)
SUBJECT=$(head -n 1 $1)
if echo "$SUBJECT" | grep -q "\b$ISSUE_KEY\b" ; then
    # issue key already present in the message
case $2 in
	message)	echo -n "$ISSUE_KEY " >$1
	template)	;;
	squash)		;;
	merge)		;;
	*)			echo "#$ISSUE_KEY " >$1
echo "$TPL">>$1

This also works with tools like SourceTree. Notice the extra # in case a commit editor is used, The user is supposed to remove the hashtag and add more text. We do this to disallow developers to just hit save.

Much appreciated Mike! Would you be able to provide some high level on setup/usage?

Just copy that file as prepare-commit-msg into .git/hooks. No special usage instruction, everything should work the same. The issue id will appear in commit message subjects if they are in branchnames (in the syntax as created by JIRA)

For SourceTree you write the commit message and the issue id will appear afterwards, after committing. For the git command line when using a commit editor, you will see the issue id in the editor.

This is very helpful...thanks!

Works a treat! Thanks Mike!

Hmm...for some reason it's not working for me. 1. I've tried running both with git commit and git commit -m 'test commit' 2. My branchname is in the format "release-PROJECTNAME-1-test-commit" What could I be missing?

Justin - how did you get it to work?

I just dropped it into .git/hooks

I had done that too. Could my script be wrong? What did Mike mean by "Notice the extra # in case a commit editor is used..." ?

He just means that the issue key is prefixed with # in the commit message.

Having the JIRA issue-id in the commit message is the right thing to do.

In git it is normal in several branching models (e.g. gitflow) to delete branches once they are merged. Only the commits themself are persistent. You only need to "copy" the ids into the merge commit if you use a squash merge strategy. But then you need to copy heach commits headline anyway.

We use a commit message hook to auto-prepend commit messages with the issue-id from the branch name. With that developers only need to create branches inside JIRA and dont need to type the issue IDs anywhere.

Mike, this sounds immensely helpful. What did you get this "hook", or was it custom created?

Thank you Mike. Are you using a traditional git hook in each repository, or did you configure a hook in Stash? I don't see any obvious plugins/hooks in the marketplace for the later, so I guess I'll come up with a regex and some bash to implement the former.

I edited my question to ask how this fits in:

Sounds like we shouldn't need to include any comments to have plan branches linked back to JIRA issues. The default branch naming convention appears to satisfy the "Integrating branches with JIRA" section.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,913 views 19 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you