Jira issue key in commit message in SourceTree and recognizing it in bamboo build

What the easiest way to add JIRA key in commit message in Source Tree, can SourceTree get the key from the branch name?

Why bamboo doesn't recognize Jira key from merge commit with branch name like "Merge branch/JIRA-KEY-issue"?

1 answer

1 accepted

I decided to add client commit-msg hook, which automatically adds JIRA Key in commit message from branch name, and checks JIRA Key in message

 

Linux
 
#!/bin/bash
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
if [[ $BRANCH_NAME =~ KEY-[0-9]+ ]]; then
   echo -e "\n"$BASH_REMATCH >> $1
fi
if ! grep -Pq "KEY-[0-9]{4,}" $1; then
    echo "Aborting commit due to commit message without JIRA-key."
    exit 1
fi


Windows
 
#!/bin/bash
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
TR=$(echo $BRANCH_NAME | sed -r 's/.*(KEY-[0-9]{4,}).*/\1/')
if [[ -n $TR ]]; then
echo -e "\n"$TR >> $1
fi
if ! grep -Eq "KEY-[0-9]{4,}" $1; then
    echo "Aborting commit due to commit message without JIRA-key."
    exit 1
fi

 

 

where 

KEY-[0-9]{4,} - JIRA Key with not less than 4 numbers 

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

262 views 0 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot