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

This widget could not be displayed.

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 Sign up to answer
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

879 views 2 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