3 回答
- 321
URLは皆さんが紹介しているので、参考となる具体的なコードでも…
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.config.util.JiraHome; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.PrintWriter; import java.io.IOException; /** https://scriptrunner.adaptavist.com/5.0.17/jira/listeners.html 「The event object will be passed to the script in the binding. For issue related events, this will be an IssueEvent. So the simplest listener might look like:」 よりScript Listenersの場合イベントオブジェクトが event 変数名で渡されるためその変数から 操作された課題を getIssue メソッドで取得します。 https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/event/issue/IssueEvent.html */ Issue issue = event.getIssue(); /* 以下はScript Consoleでのテスト用 */ //Issue issue = ComponentAccessor.getIssueManager().getIssueObject("<課題キー>"); /** ①カスタムフィールドの値の取得 <フィールドID> は、取得したいカスタムフィールドのIDを指定する必要があります。 カスタムフィールドIDの確認方法は、JIRA管理画面のURLとかで確認してください。 getCustomFieldValueでString型に無条件でキャストしていますが カスタムフィールドによって返却されるオブジェクトは異なります。 文字列フィールドだと String 数値フィールドだと Double ユーザーピッカー単一だと com.atlassian.jira.user.ApplicationUser 複数選択だと List<com.atlassian.jira.user.ApplicationUser> https://docs.atlassian.com/jira/7.4.1/com/atlassian/jira/user/ApplicationUser.html グループピッカー単一だと com.atlassian.crowd.embedded.api.Group 複数選択だと List<com.atlassian.crowd.embedded.api.Group> 選択・チェックボックスとかだと com.atlassian.jira.issue.customfields.option.Option 複数選択だと List<com.atlassian.jira.issue.customfields.option.Option> https://docs.atlassian.com/jira/7.4.1/com/atlassian/jira/issue/customfields/option/Option.html あたりです。 導入しているアドオンによっては他にもバリエーションあるので 細かくは実際にデバックしながら確認してください */ CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField csvFiled = customFieldManager.getCustomFieldObject(<フィールドID>); String value = (String)issue.getCustomFieldValue(csvFiled); /** ②csv出力 https://docs.atlassian.com/jira/7.4.1/com/atlassian/jira/config/util/JiraHome.html APIよりJIRAホームディレクトリのexportディレクトリパスを取得して そこにtest.csvファイルを出力してみる */ File exportDirectory = ComponentAccessor.getComponentOfType(JiraHome.class).getExportDirectory(); File csvFile = new File(exportDirectory, "test.csv"); /** CSV出力用のライブラリなどを使ったほうがよいかと思いますが 細かい説明は割愛しますが外部のライブラリは環境によっては使用できない可能性もあるのでご注意を。 */ PrintWriter pw = null; try { pw = new PrintWriter(new BufferedWriter(new FileWriter(csvFile))); pw.write(value + "," + value + "," + value); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (pw != null) { pw.close(); } }
カスタムフィールドのフィールドIDは、JIRA管理画面のカスタムフィールド 画面から
確認したいカスタムフィールドを編集すれば、URLに表示されます。
以下スクリーンショットだと 11705 ですね。
- 釜谷 宙
ご回答ありがとうございました。
ご提示の手法を試してうまくcsv出力することができました。
コメントを追加... - 210
ワークフローのステータス進行をトリガーにしたいのであれば、Workflow Examples の Post Functions Examples が参考になるかもしれません。
リスナーであれば、課題更新などのイベントをトリガーにすることになるので、Listeners あたりが参考になるでしょうか。
ワークフロー、リスナーいずれを使用する場合でも、カスタムフィールド値の取得は標準的な JIRA Java API を使うことになると思いますので、Atlassian Developers が参考になるのではないでしょうか。
https://developer.atlassian.com/jiradev/jira-apis
コメントを追加... - 210
Script Listeners というは、アドオンの Script Runner で作るリスナーでしょうか?それでしたら、
①カスタムフィールドの値の取得
は以下が参考になるかと思います。
https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/33030170/Post+Functions
②csv出力
については、Groovy csv で Google で検索すると色々サンプルが出てきますが、如何でしょうか?
コメントを追加...
JIRAのワークフロー進行をトリガーとして
当該チケットのカスタムフィールドに入力された値をcsvファイルに書き出したいと考えています。
その際使用する、以下の2点の Script Listeners での書き方が不明です。
①カスタムフィールドの値の取得
②csv出力
具体的なコードでなくても、参考となるURLなどでもかまいませんので、
ご教示いただけますよう、よろしくお願いします。