Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automatically add a comment

Karrie Dash May 22, 2017

I am using Groovy Scriptrunner. How can I add a comment that says, "In UAT" when a transition is completed for an issue?

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2017

Hey Karrie!

I've coded up a simple example for you to use here:

import com.atlassian.jira.component.ComponentAccessor

//Get appropriate managers/handlers
def commentManager = ComponentAccessor.getCommentManager()
def authContext = ComponentAccessor.getJiraAuthenticationContext()

//Define currentUser because it is not an available default
def currentUser = authContext.getLoggedInUser()

//Add comment to issue transitioned. The name on the comment will be the current user's name.
//The boolean value delegates whether or not an event is fired.
commentManager.create(issue, currentUser, "This is where the comment goes!", true)

Steps to use in transition:

  • Go to the workflow of the project that you would like this functionality to be present in.
  • Edit the workflow in Diagram view.
  • Click on the transition that you would like to add it to.
  • Choose Post-Function in the pop-up that appears to the right of the screen.
  • Choose to add a new Post-Function and then select "Script Post-Function" and hit "Add"
  • Then choose a "Custom Script Post-Function"
  • You then add the code, or something similar, in the Inline Script box (add a relivent note).
  • After you add the Post-Function, ensure that it is the very last script ran by pushing it down to the very bottom of the diolog box that reads "The following will be processed after the transition occurs."
  • You may then publish the workflow and you're good to go.

The script that I provided above is a very simple example, but you can add more complex properties to the comment or add make a default user to be the commenter if you like (etc...). You can see other possible methods to use in the JIRA API.

Karrie Dash May 25, 2017

Thank you!! That worked perfectly!

Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2017

No problem, if you have any other questions let me know! :)

0 votes
Marlene Vitale March 19, 2019

Do you know how to do this with Jira and scriptrunner cloud?

TAGS
AUG Leaders

Atlassian Community Events