In this page
Logging work on an issue
This automation creates a worklog on an issue by parsing the duration and the optional work description (worklog comment) from the VCS commit message:
Note that the work description is not the complete commit message, but the part after the @time 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 Log work, and click Save.
- Click New action.
- Select the action Run Groovy script.
- Enter "Log work as committer" to the Description field.
-
Enter this Groovy script:
import com.atlassian.jira.bc.JiraServiceContextImpl import com.atlassian.jira.bc.issue.worklog.WorklogInputParametersImpl import com.atlassian.jira.bc.issue.worklog.WorklogService 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 worklogService = ComponentAccessor.getOSGiComponentInstanceOfType(WorklogService.class) def jiraServiceContext = new JiraServiceContextImpl(author) issues.each { issue -> def worklogInput = WorklogInputParametersImpl.builder() .issue(issue) .comment(devops.comment) .startDate(new Date()) .timeSpent(devops.duration) .build() def worklogResult = worklogService.validateCreate(jiraServiceContext, worklogInput) if (worklogResult) { worklogService.createAndAutoAdjustRemainingEstimate(jiraServiceContext, worklogResult, true) auditLog.addAssociatedIssue(issue) auditLog.addAssociatedUser(author) auditLog.info("Worklog added to ${issue.key}") } else { throw new IllegalArgumentException(jiraServiceContext.getErrorCollection().toString()) } }
- Click Save.
- Click New action.
- Select the action Log work.
- Enter {{devops.duration}} in the Time spent field.
- Enter {{now}} in the Date started field.
- Enter {{devops.comment}} in the Work description field.
- Click Save.
- Name your automation rule intuitively, and click Turn it on.
Usage
Time only
-
Create a commit with this commit message (no work description entered!):
Add extended logging for the FOO-1 bug. @time 2h 30m
Learn more about the expected time format here. - A new worklog will be added to the issue FOO-1, with 2.5 hours and without any work description.
Time with work description
-
Create a commit with this commit message:
Add extended logging for the FOO-1 bug. @time 2h 30m I investigated the root cause.
Learn more about the expected time format here. - A new worklog will be added to the issue FOO-1, with 2.5 hours and with the work description "I investigated the root cause."
Troubleshooting
If you don't get the expected results:
- Check if the @time command is defined in the Genius Commands screen? (It's a default command.)
- Check if the @time command followed by the duration (and optionally the work description) was included in the commit message?
- See the general troubleshooting steps.
Questions?
Ask us any time.