Integrating with custom JIRA issue key in Bitbucket

お困りですか?

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

コミュニティに質問

プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。

このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

問題

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

原因

Bitbucket passes commit messages through a regex pattern to identify and create links. The default format is two or more uppercase letters ([A-Z][A-Z]+), followed by a hyphen and the issue number (e.g. "TEST-123").

This regex for matching Jira issue keys has changed over time, multiple versions are provided below.

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

(info) Note: with this pattern, issue keys are recognized if they are preceded by any of the following:

  • beginning of a line
  • a lowercase letter followed by a dash
  • whitespace or punctuation character, excluding a dash
Version 3.10 and below
((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)

If a custom issue key format is specified in JIRA, the custom format also needs to be configured in Bitbucket.

ソリューション

Follow the steps below to modify the regex pattern:

  1. Shut down Bitbucket
  2. Edit the contents of the <Bitbucket installation directory>/bin/setenv.sh or <Bitbucket 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
  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:

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_])"


(info) Bitbucket Server 5.0+ では setenv と環境変数に変更があります

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 (or start-bitbucket.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:
Example

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 :

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 does not match exactly the one specified in JIRA, in Bitbucket it is required to add the -\d suffix to the JIRA one

Changing the Jira key pattern here does not affect the hyperlinks generated on commit messages, but only the indexed commit messages that are gathered to display issues in the 'Issues' column.

See the following for more details: BSERV-10930 The web UI does not honor custom Jira issue patterns

最終更新日 2025 年 4 月 15 日

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

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