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

Justin Florentine May 12, 2015

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: https://confluence.atlassian.com/display/BAMBOO057/Using+plan+branches#Usingplanbranches-configurebranch the commit message should not be necessary, at least for the linking of plan branches back to JIRA issues.

4 answers

1 vote
Mike Friedrich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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

#!/bin/sh
#
# check if commit is merge commit
if [ "$2" == "merge" ]; then
    exit
fi
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
    exit
fi
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
    exit
fi
case $2 in
	message)	echo -n "$ISSUE_KEY " >$1
				;;
	template)	;;
	squash)		;;
	merge)		;;
	*)			echo "#$ISSUE_KEY " >$1
				;;
esac
echo "$TPL">>$1
exit

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.

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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

Mike Friedrich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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)

Mike Friedrich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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.

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

This is very helpful...thanks!

Justin Florentine May 12, 2015

Works a treat! Thanks Mike!

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2015

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?

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2015

Justin - how did you get it to work?

Justin Florentine May 20, 2015

I just dropped it into .git/hooks

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2015

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..." ?

Justin Florentine May 20, 2015

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

0 votes
Justin Florentine May 13, 2015

I edited my question to ask how this fits in:

https://confluence.atlassian.com/display/BAMBOO057/Using+plan+branches#Usingplanbranches-configurebranch

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.

0 votes
Justin Florentine May 12, 2015

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.

0 votes
Mike Friedrich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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.

Ron Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2015

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

Suggest an answer

Log in or Sign up to answer