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

  1. Login to Jira as admin, go to AdministrationSystemAutomation rules.
  2. Click Create rule.
  3. Select the trigger Genius Commit created (from the DevOps category).
  4. Choose the command Log work, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Log work as committer" to the Description field.
    2. 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())
      	}
      }
      
  7. Click Save.
  8. Click New action.
  9. Select the action Log work.
    1. Enter {{devops.duration}} in the Time spent field.
    2. Enter {{now}} in the Date started field.
    3. Enter {{devops.comment}} in the Work description field.
  10. Click Save.
  11. Name your automation rule intuitively, and click Turn it on.

Usage

Time only
  1. 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.
  2. A new worklog will be added to the issue FOO-1, with 2.5 hours and without any work description.
Time with work description
  1. 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.
  2. 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:

  1. Check if the @time command is defined in the Genius Commands screen? (It's a default command.)
  2. Check if the @time command followed by the duration (and optionally the work description) was included in the commit message?
  3. See the general troubleshooting steps.

Questions?

Ask us any time.