In this page

Updating the priority of an issue

This automation updates the priority of an issue by parsing the new priority name from the commit message.

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 Set issue priority, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set issue priority" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      def priorityId = jiraHelper.getPriorityByName(devops.priority).id
      
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value reference!)
      
      issues.forEach { issue ->
      	if (issue.priorityObject.id == priorityId) {
      		return
      	}
      	try {
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setPriorityId(priorityId)
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			auditLog.info("Priority of ${issue.key} successfully changed to <${issueResult.issue.priorityObject.name}>.")
      		} else {
      			validationResult.errorCollection.errorMessages.each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
  7. Click Save.
  8. Click New action.
  9. Select the action Edit issue.
    1. Select Priority from the Choose fields to set... dropdown.
    2. Click inside the Priority field and enter {{jiraHelper.getPriorityByName(devops.priority).id}}.
  10. Click Save.
  11. Name your automation rule intuitively, and click Turn it on.

Usage

  1. Create a commit with this commit message:
    Add a unit test to reproduce the FOO-1 bug. @priority High
  2. The priority of the issue FOO-1 will change to "High".

Troubleshooting

If you don't get the expected results:

  1. Check if the @priority command is defined in the Genius Commands screen? (It's a default command.)
  2. Check if the @priority command followed by the name of the priority was included in the commit message?
  3. See the general troubleshooting steps.

Updating the type of an issue

This automation updates the type of an issue by parsing the new issue type name from the commit message.

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 Set issue type, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set issue type" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      def issueTypeId = jiraHelper.getIssueTypeByName(devops.issuetype).id
      
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value reference!)
      
      issues.forEach { issue ->
      	if (issue.issueType.id == issueTypeId) {
      		return
      	}
      	try {
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setIssueTypeId(issueTypeId)
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			auditLog.info("Type of ${issue.key} successfully changed to <${issueResult.issue.issueType.name}>.")
      		} else {
      			validationResult.errorCollection.errorMessages.each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
  7. Click Save.
  8. Click New action.
  9. Select the action Edit issue.
    1. Leave the dropdown empty and click More options instead.
    2. Enter the following content in the Additional fields:
      {
          "fields": {
              "issuetype": {
                  "id": "{{jiraHelper.getIssueTypeByName(devops.issuetype).id}}"
              }
          }
      }
      
  10. Click Save.
  11. Name your automation rule intuitively, and click Turn it on.

Usage

  1. Create a commit with this commit message:
    Protect against the null value that caused the FOO-1 bug. @issuetype Bug
  2. The type of the issue FOO-1 will change to "Bug".

Troubleshooting

If you don't get the expected results:

  1. Check if the @issuetype command is defined in the Genius Commands screen? (It's a default command.)
  2. Check if the @issuetype command followed by the name of the issue type was included in the commit message?
  3. See the general troubleshooting steps.

Updating an issue field value

This automation updates the value of an arbitrary issue field (including system fields and custom fields) by using a custom command and parsing the value from the commit message.

Configuration

This guide assumes that you have a number-type custom field "Urgency", it is already associated to the issue screen, and you want to update its value from the commit message. You can implement the automation for any field based on this guide, just use a different command and different parameters.

  1. Create the custom command:
    1. Login to Jira as admin, go to CommitsGenius Commands.
    2. Click Add command.
    3. Enter the command name "Set urgency".
    4. Enter the command "urgency".
    5. Enter the regular expression (?<level>[1-5]) as parameter pattern. (It will accept an integer between 1 and 5 and will make that available as the smart value {{devops.level}}.)
    6. Click Save.
  2. Create the automation rule:
    1. Follow the instructions in the updating the priority of an issue guide above with the following differences:
      1. In step 4, choose the custom command "Set urgency".
      2. In step 5:
        1. Enter this Groovy script:
          import com.atlassian.jira.component.ComponentAccessor
          
          def issueService = ComponentAccessor.issueService
          def userManager = ComponentAccessor.userManager
          def customFieldManager = ComponentAccessor.customFieldManager
          
          def urgencyCustomField = customFieldManager.getCustomFieldObjectByName("Urgency")
          
          def author = devops.committerByUsername
          // def author = devops.committerByEmailAddress (alternative, see the Smart Value reference!)
          
          issues.forEach { issue ->
          	try {
          		def issueParams = issueService.newIssueInputParameters()
          		issueParams.addCustomFieldValue(urgencyCustomField.id, devops.level)
          
          		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
          		if (validationResult.isValid()) {
          			def issueResult = issueService.update(author, validationResult)
          			auditLog.info("Urgency of ${issue.key} successfully changed to <${issueResult.issue.getCustomFieldValue(urgencyCustomField)}>.")
          		} else {
          			validationResult.errorCollection.errorMessages.each { auditLog.error(it) }
          		}
          	} catch (Exception e) {
          		auditLog.error(e.message)
          	}
          }
          
        2. Choose the "Urgency" field and the smart value {{devops.level}}.
        3. If the field is not available in the dropdown or if it is not allowed to enter smart values, follow the JSON-based approach which is described in step 6 of the updating the issue type guide. The following JSON can be used to update the "Urgency" custom field:
          {
              "fields": {
                  "Urgency": {{devops.level}}
              }
          }
          

Usage

  1. Create a commit with this commit message:
    Add a unit test to reproduce the FOO-1 bug. @urgency 4
  2. The "Urgency" field of the issue FOO-1 will change to 4.

Troubleshooting

If you don't get the expected results:

  1. Check if the @urgency command is defined in the Genius Commands screen? (It's a default command.)
  2. Check if the @urgency command followed by the urgency level (an integer between 1 and 5) was included in the commit message?
  3. See the general troubleshooting steps.

Assigning an issue

This automation updates the assignee of an issue by parsing the new assignee's username from the commit message:

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 Assign issue, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set assignee" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      def assignee = jiraHelper.getUserByName(devops.assignee)
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value reference!)
      
      issues.forEach { issue ->
      	if (issue.assignee?.id == assignee.id) {
      		return
      	}
      	try {
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setAssigneeId(devops.assignee)
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			auditLog.info("Assignee of ${issue.key} successfully changed to <${issueResult.issue.assignee.displayName}>.")
      		} else {
      			validationResult.errorCollection.errorMessages.each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
  7. Click Save.
  8. Click New action.
  9. Select the action Assign issue.
    1. Select Smart value from the Assign the issue to dropdown.
    2. Click inside the User field and enter {{jiraHelper.getUserByName(devops.assignee).key}}.
  10. Click Save.
  11. Name your automation rule intuitively, and click Turn it on.

Usage

  1. Make sure that the user "bob" exists Jira.
  2. Create a commit with this commit message:
    Add a unit test to reproduce the FOO-1 bug. @assign bob
  3. The assignee of the issue FOO-1 will change to "bob".

Troubleshooting

If you don't get the expected results:

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

Automatically assigning an issue to the committer

This automation updates the assignee of an issue to the committer if the issue was unassigned. (It doesn't require anything explicit in the commit.)

Configuration

  1. Login to Jira as admin, go to AdministrationSystemAutomation rules.
  2. Click Create rule.
  3. Select the trigger Changeset accepted (from the DevOps category).
  4. Click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set assignee" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      issues.forEach { issue ->
      	if (issue.assignee) {
      		return
      	}
      	try {
      		def author = devops.changeset.commits.stream()
      				.filter { commit -> commit.message.contains(issue.key) }
      				.findFirst()
      				.map { commit -> changesetHelper.parseCommitAuthor(commit).name }
      				.map { committer -> userManager.getUserByName(committer) }
      				.orElse(devops.actor)
      
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setAssigneeId(author.username)
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			auditLog.info("Assignee of ${issue.key} successfully changed to <${issueResult.issue.assignee.displayName}>.")
      		} else {
      			validationResult.errorCollection.errorMessages.each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
  7. Click Save.
  8. Click Add component and select New condition.
  9. Select the condition Issue fields condition.
    1. Select Assignee from the Field dropdown.
    2. Select is empty from the Condition dropdown.
  10. Click Save.
  11. Click New action.
  12. Select the action Assign issue.
    1. Select Smart value from the Assign the issue to dropdown.
    2. Click inside the User field and enter {{changesetHelper.parseCommitAuthor(devops.changeset.commits.first).key}}.
  13. Click Save.
  14. Name your automation rule intuitively, and click Turn it on.

Usage

  1. Make sure that the user with username (not full name) "bob" exists Jira.
  2. Make sure that your VCS username is "bob" (i.e. the committer of future commits will be "bob"). For example, in case of Git, check the Git username.
  3. Create a commit with this commit message:
    Add a unit test to reproduce the FOO-1 bug.
  4. The assignee of the issue FOO-1 will change to "bob".

Troubleshooting

If you don't get the expected results:

  1. See the general troubleshooting steps.

Questions?

Ask us any time.