Jira – Extract the key from the commit

Sometimes, we need to get a Jira key for later usage.

For example, we can need it to do some release notes or other things.

This is the regex that I use with an example of usage.

Regex

You need to replace PRJ by your project:

'((PRJ-)+([0-9]*)?)'

Example of usage

Extract the Jira key from all commits between 2 tags:

git log rs420..rs422  --pretty=oneline | grep -oE '((PRJ-)+([0-9]*)?)' | sort -u

This permits us to obtain a clear list like:

PRJ-4056
PRJ-4057
PRJ-4105
PRJ-4189

The job is done, very easily and can be used for a lot of things like interacting with Jira API if needed.