In this page
Adding a comment to an issue
Configuration
Usage
Single-line commit message
Multi-line commit message
Multi-line commit message with markup
Troubleshooting
Configuration
Usage
Single-line commit message
Multi-line commit message
Multi-line commit message with markup
Troubleshooting
Adding a comment to an issue
This automation adds a comment to an issue by parsing the comment text from the VCS commit message:
Note that the issue comment text is not the complete commit message, but the part after the @comment command.
Configuration
- Login to Jira as admin, go to Administration → System → Automation rules.
- Click Create rule.
- Select the trigger Genius Commit created (from the DevOps category).
- Choose the command Comment issue, and click Save.
- Click New action.
- Select the action Run Groovy script.
- Enter "Add comment as committer" to the Description field.
-
Enter this Groovy script:
import com.atlassian.jira.bc.issue.comment.CommentService import com.atlassian.jira.bc.issue.comment.CommentService.CommentParameters import com.atlassian.jira.component.ComponentAccessor def author = devops.committerByUsername ?: {throw new IllegalArgumentException("No user found with username \"${devops.commit.username}\"")}() // def author = devops.committerByEmailAddress ?: {throw new IllegalArgumentException("No user found with email address \"${devops.commit.emailAddress}\"")}() // (alternative, see the Smart Value Reference!) def commentService = ComponentAccessor.getOSGiComponentInstanceOfType(CommentService) issues.each { issue -> def commentInput = CommentParameters.builder() .issue(issue) .body(devops.comment) .created(new Date()) .author(author) .build() def commentResult = commentService.validateCommentCreate(author, commentInput) if (commentResult.valid) { commentService.create(author, commentResult, true) auditLog.addAssociatedIssue(issue) auditLog.addAssociatedUser(author) auditLog.info("Comment added to ${issue.key}") } else { throw new IllegalArgumentException(commentResult.getErrorCollection().toString()) } }
- Click Save.
- Click New action.
- Select the action Comment on issue.
- Enter the comment content. Use the smart value {{devops.comment}} to refer to the text that is entered to the commit message after the @comment command.
- Click Save.
- Name your automation rule intuitively, and click Turn it on.
Usage
Single-line commit message
-
Create a commit with this commit message:
Protect against the null value that caused the FOO-1 bug. @comment Bug fixed!
-
This comment will be added to the issue FOO-1:
Bug fixed!
Multi-line commit message
-
Create a commit with this commit message:
Protect against the null value that caused the FOO-1 bug. @comment Bug fixed! (It was caused by an unexpected null value.)
-
This comment will be added to the issue FOO-1:
Bug fixed! (It was caused by an unexpected null value.)
Multi-line commit message with markup
-
In case you want to use formatting, you can use the Jira text formatting notation (wiki markup) in the commit messages!
Create a commit with this commit message:
Protect against the null value that caused the FOO-1 bug. @comment Affected input fields in the [Acme sign-up form|https://www.acme.com/sign-up]: * First name * Last name * Age
-
This comment will be added to the issue FOO-1:
Affected input fields in the Acme sign-up form: • First name • Last name • Age
...where "Acme sign-up form" is a link with list items below it!
Troubleshooting
If you don't get the expected results:
- Check if the @comment command is defined in the Genius Commands screen? (It's a default command.)
- Check if the @comment command followed by the comment text was included in the commit message?
- See the general troubleshooting steps.
Questions?
Ask us any time.