Groovy スクリプト

このページの内容

お困りですか?

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

コミュニティに質問

Groovy スクリプトは、条件とバリデータでも事後操作でも実行できます。強力で柔軟性の高い機能ですが、上級ユーザー向けです。

If you've enabled Groovy console or you're on Jira Service Management version lower than 5.16, refer to our previous documentation on configuring Groovy scripts.

Groovy scripts page in Assets configuration section

始める前に

Here’s some things to be know before you start using Groovy scripts:

  • You’ll need to be a Jira admin or Jira system administrator.
  • To start using Groovy scripts across Assets, add your scripts to the following directory in the shared home.
    <JIRA_SHARED_HOME>/plugins/assets/groovy_scripts
    You can also store the scripts within subdirectories of the above path and if you wish to store the files in a different location, create symbolic links
  • Make sure that the directory, the subdirectories where your Groovy scripts are located, and your Groovy script files are readable and executable by the user running Jira. We recommend that you limit the user accounts who can access the scripts directory.
  • Make sure to test your scripts in a non-production environment, before you run them in your production environment.

View and run a Groovy script

Once you’ve added a script to the script directory in the shared home, you can view the script contents and run the script.

You can also use any files added to the allowlist in the Groovy script configuration page before your upgrade to Jira Service Management 5.16.x. A read-only list of these scripts is available in the Groovy scripts page.

To view and run a script:

  1. Go to Administration  then Manage apps.
  2. Select Groovy scripts then View and run scripts.
  3. In the Script path field, enter the absolute file path. Paths can also be relative to the script directory.
    For allowlist scripts, enter the absolute file path.

  4. (optional) Add other details such as the Issue key and Object key.

  5. Select Run script.

You can also view and run scripts from other areas of Assets such as workflow transitions and object schema automations. Note that Assets Schema managers can also configure Groovy scripts within object schema automations.

Scripts paths with a prefix of {JWD} are files that you’ve stored relative to the Jira working directory before upgrading to Jira Service Management 5.16.


How to enable the Groovy script console

Starting from Jira Service Management 5.16x, the Groovy script console present in earlier versions is not available by default in Assets. Although you can use groovy console, to minimize potential security risks associated with arbitrary code execution, we advise against using it.

Here’s some things to know before you enable the console:

  • You can add or remove allowlist files in the Assets allowlist page.
  • You can continue to use files within the script directory across Assets even after you enable the console.
  • If you’re using scripts in post functions for Workflows, make sure to add them to the allowlist or the script directory.
  • Any script paths you’ve specified within Workflows (conditions, validators, post functions) will work but you can’t modify the script paths. 

To enable the groovy console feature flag, set the following system property. How to set system properties

assets.groovy.console.enabled = true

Variables

Groovy スクリプトを追加する際は、アセット ワークフロー関数には次の変数が事前に定義されているため、スクリプトでこれらを使用できます。

変数説明
課題トランジションする課題。
originalIssue

元の課題。

課題の属性を条件として使用できます。たとえば、担当者が変わったときに何らかの動作が必要な場合は、条件で次のコードを使用します。

issue.assignee != originalIssue.assignee
現在のユーザー

現在の Jira ユーザー。

報告者が現在のユーザーかどうかを確認するには、次のコードを使用します。

currentUser == issue.reporter
log

ログ フレームワーク。次のようにして atlassian-jira.log にログを記録できます。

log.warn("This is a warning!");


If you're looking for some inspiration and examples, see Groovy script examples.

最終更新日 2024 年 5 月 9 日

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

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