Integrating with custom JIRA issue key

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

問題

JIRA has a UI to help specify a custom issue key format. When integrating with Bitbucket Server, these custom JIRA issue keys are not recognized by Bitbucket Server and hence commits are not linked to the JIRA issues.

原因

Bitbucket Server passes commit messages through a regex pattern to identify and create links. The custom JIRA issue key format will not work with the default pattern that Bitbucket Server is shipped with. This regex has changed over time, multiple versions are provided below.

Version 3.11+
(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([A-Z][A-Z0-9_]*-\d+)(?![^\W_])
Version 3.10 and below
((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)

ソリューション

Follow the steps below to modify the regex pattern:

1) Shut down Bitbucket Server.

2) Edit the contents of the <Bitbucket Server installation directory>/bin/setenv.sh or <Bitbucket Server installation directory>/bin/setenv.bat (depending upon your OS) and add the modified regex to the variable JVM_SUPPORT_RECOMMENDED_ARGS.

3) Save the file.

4) Remove the contents of the following folder:

バージョン Folder location
Up to 2.10.x <BITBUCKET_HOME>/caches/idx-snapshots
2.11 以降 <BITBUCKET_HOME>/data/snapshots
3.2 以降 <BITBUCKET_HOME>/shared/data/snapshots


5) Restart Bitbucket Server.

6) Push to the repository with the JIRA issue key in the commit message to force a reindex of the data.


For example, to match JIRA keys such as C001-1 or ABC123-1, set the variable as follows:

Pre 2.8:

JVM_SUPPORT_RECOMMENDED_ARGS="-Dstash.jira.key.pattern=\"((?<!([A-Z0-9]{1,10})-?)[A-Z0-9]+-\d+)\""

2.8 以降

JVM_SUPPORT_RECOMMENDED_ARGS="-Dintegration.jira.key.pattern=\"((?<!([A-Z0-9]{1,10})-?)[A-Z0-9]+-\d+)\""

5.0 以降

JVM_SUPPORT_RECOMMENDED_ARGS="-Dintegration.jira.key.pattern=((?<!([A-Z0-9]{1,10})-?)[A-Z0-9]+-\d+)"


To match JIRA both uppercased and lowercased JIRA keys, set the variable as follows:

JVM_SUPPORT_RECOMMENDED_ARGS="-Dintegration.jira.key.pattern=\"(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([a-zA-Z][a-zA-Z0-9_]*-\d+)(?![^\W_])\""

5.0 以降

JVM_SUPPORT_RECOMMENDED_ARGS="-Dintegration.jira.key.pattern= (?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([a-zA-Z][a-zA-Z0-9_]*-\d+)(?![^\W_])"


setenv and environment variable changes in Bitbucket Server 5.0+

Starting with Bitbucket Server 5.0, setenv.sh and setenv.bat have been removed. The options that were set in this file can now be set via environment variables. Where to set the environment variable depends on which Operating System you're running on.

Linux

When using the atlbitbucket service on Linux, the environment variables are ignored. You must set the parameters in _start-webapp.sh. These values will be read when the service starts.

As an example, to set JVM_SUPPORT_RECOMMENDED_ARGS, you would add this line to the file:

JVM_SUPPORT_RECOMMENDED_ARGS=-XX:+HeapDumpOnOutOfMemoryError

Windows

Set the parameter as an environment variable for the user running Bitbucket Server. For example, if you want to set JVM_SUPPORT_RECOMMENDED_ARGS, create it as an environment variable and assign the appropriate value to it. When Bitbucket Server starts using the startup scripts or service, it will pick up and apply this value.

If the parameter is set correctly the following line will be logged in the <BITBUCKET_HOME>/log/atlassian-bitbucket.log:

c.a.i.i.jira.PatternJiraKeyScanner Using custom Jira key pattern: ((?<!([A-Z0-9]{1,10})-?)[A-Z0-9]+-\d+)

Or the following in older versions of Bitbucket Server:

c.a.s.i.jira.idx.JiraKeyIndexer Using custom JIRA key pattern: ((?<!([A-Z0-9]{1,10})-?)[A-Z0-9]+-\d+)

(info) the regex in Bitbucket Server does not match exactly the one specified in JIRA, in Bitbucket Server it is required to add the -\d suffix to the JIRA one

最終更新日 2018 年 11 月 2 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.