In this page

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)
      			if (issueResult.issue.assignee?.id == assignee.id) {
      				auditLog.info("${issue.key} assignee updated to <${issueResult.issue.assignee.displayName}>")
      			} else {
      				auditLog.error("${issue.key} assignee not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + 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)
      			if (issueResult.issue.assignee) {
      				auditLog.info("${issue.key} assignee updated to <${issueResult.issue.assignee.displayName}>")
      			} else {
      				auditLog.error("${issue.key} assignee not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + 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.

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)
      			if (issueResult.issue.priorityObject.id == priorityId) {
      				auditLog.info("${issue.key} priority updated to <${issueResult.issue.priorityObject.name}>")
      			} else {
      				auditLog.error("${issue.key} priority not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + 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)
      			if (issueResult.issue.issueType.id == issueTypeId) {
      				auditLog.info("${issue.key} type updated to <${issueResult.issue.issueType.name}>")
      			} else {
      				auditLog.error("${issue.key} type not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + 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 the labels of an issue

This automation updates the Labels field of an issue by parsing the new labels' names 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 labels, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set labels" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.bc.issue.label.LabelService
      
      def mode = "set" // "set": overwrite old labels, "add": add new labels to the old ones
      def delimiter = "," // delimiter character (separates label names)
      
      def userManager = ComponentAccessor.userManager
      def labelService = ComponentAccessor.getComponent(LabelService)
      
      def labels = devops.label.split(delimiter).collect { it.trim() }
      
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value Reference!)
      
      issues.forEach { issue ->
      	try {
      		if (mode == "add") {
      			labels.addAll(issue.labels.collect { it.label })
      		}
      		labels.unique()
      
      		def validationResult = labelService.validateSetLabels(author, issue.id, labels as Set)
      		if (validationResult.isValid()) {
      			def labelsResult = labelService.setLabels(author, validationResult, true, true)
      			if ((labelsResult.labels.collect { it.label } as Set) == (labels as Set)) {
      				auditLog.info("${issue.key} labels updated to <${labels.join(', ')}>")
      			} else {
      				auditLog.error("${issue.key} labels not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + validationResult.errorCollection.errorMessages).each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
      Notes:
      • You can configure mode in the top part of the script.
      • You can also configure delimiter, the preferred separator character between label names.
  7. Click Save.
  8. Name your automation rule intuitively, and click Turn it on.

Although this automation could be implemented with the built-in actions, the solution would be over-complicated. It's because the field is a multi-value one and a complete solution should support both the "set" and "add" operations.

← See the other tab for the Groovy script based solution.

Usage

  1. Create a commit with this commit message:
    Fix the FOO-1 bug. @label security, performance
  2. The labels of the issue FOO-1 will change to "security" and "performance".

Troubleshooting

If you don't get the expected results:

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

Updating the affects versions of an issue

This automation updates the Affects Version/s field of an issue by parsing the new version names 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 affects versions, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set affects versions" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.issue.IssueInputParametersImpl
      
      def mode = "set" // "set": overwrite old versions, "add": add new versions to the old ones
      def delimiter = "," // delimiter character (separates version names)
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value Reference!)
      
      issues.forEach { issue ->
      	try {
      		def affectedVersionIds = devops.version.split(delimiter)
      								.collect { versionString -> jiraHelper.getVersionByName(issue.projectId, versionString.trim()).id }
      		if (mode == "add") {
      			affectedVersionIds.addAll(issue.affectedVersions.collect { it.id })
      		}
      		affectedVersionIds.unique()
      
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setAffectedVersionIds(affectedVersionIds as Long[])
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			if (issueResult.issue.affectedVersions.collect { it.id }.containsAll(affectedVersionIds)) {
      				auditLog.info("${issue.key} affects versions updated with <${issueResult.issue.affectedVersions.collect { it.name }.join(', ')}>")
      			} else {
      				auditLog.error("${issue.key} affects versions not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "Error with field <${it.key}>: ${it.value}" } + validationResult.errorCollection.errorMessages).each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
      Notes:
      • You can configure mode in the top part of the script.
      • You can also configure delimiter, the preferred separator character between version names.
  7. Click Save.
  8. Name your automation rule intuitively, and click Turn it on.

Although this automation could be implemented with the built-in actions, the solution would be over-complicated. It's because the field is a multi-value one and a complete solution should support both the "set" and "add" operations.

← See the other tab for the Groovy script based solution.

Usage

  1. Create a commit with this commit message:
    Fix the FOO-1 bug. @affectsversion 1.5.2, 1.6.0
  2. The Affects Version/s of the issue FOO-1 will change to "1.5.2" and "1.6.0".

Troubleshooting

If you don't get the expected results:

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

Updating the fix versions of an issue

This automation updates the Fix Version/s field of an issue by parsing the new version names 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 fix versions, and click Save.
  5. Click New action.
  6. Select the action Run Groovy script.
    1. Enter "Set fix versions" to the Description field.
    2. Enter this Groovy script:
      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.issue.IssueInputParametersImpl
      
      def mode = "set" // "set": overwrite old versions, "add": add new versions to the old ones
      def delimiter = "," // delimiter character (separates version names)
      
      def issueService = ComponentAccessor.issueService
      def userManager = ComponentAccessor.userManager
      
      def author = devops.committerByUsername
      // def author = devops.committerByEmailAddress (alternative, see the Smart Value Reference!)
      
      issues.forEach { issue ->
      	try {
      		def fixVersionIds = devops.version.split(delimiter)
      								.collect { versionString -> jiraHelper.getVersionByName(issue.projectId, versionString.trim()).id }
      		if (mode == "add") {
      			fixVersionIds.addAll(issue.fixVersions.collect { it.id })
      		}
      		fixVersionIds.unique()
      
      		def issueParams = issueService.newIssueInputParameters()
      		issueParams.setFixVersionIds(fixVersionIds as Long[])
      
      		def validationResult = issueService.validateUpdate(author, issue.id, issueParams)
      		if (validationResult.isValid()) {
      			def issueResult = issueService.update(author, validationResult)
      			if (issueResult.issue.fixVersions.collect { it.id }.containsAll(fixVersionIds)) {
      				auditLog.info("${issue.key} fix versions updated with <${issueResult.issue.fixVersions.collect { it.name }.join(', ')}>")
      			} else {
      				auditLog.error("${issue.key} fix versions not updated! (check the field and screen configuration!)")
      			}
      		} else {
      			(validationResult.errorCollection.errors.collect { "Error with field <${it.key}>: ${it.value}" } + validationResult.errorCollection.errorMessages).each { auditLog.error(it) }
      		}
      	} catch (Exception e) {
      		auditLog.error(e.message)
      	}
      }
      
      Notes:
      • You can configure mode in the top part of the script.
      • You can also configure delimiter, the preferred separator character between version names.
  7. Click Save.
  8. Name your automation rule intuitively, and click Turn it on.

Although this automation could be implemented with the built-in actions, the solution would be over-complicated. It's because the field is a multi-value one and a complete solution should support both the "set" and "add" operations.

← See the other tab for the Groovy script based solution.

Usage

  1. Create a commit with this commit message:
    Fix the FOO-1 bug. @fixversion 1.5.2, 1.6.0
  2. The Fix Version/s of the issue FOO-1 will change to "1.5.2" and "1.6.0".

Troubleshooting

If you don't get the expected results:

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

Updating an (arbitrary) 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("${issue.key} urgency updated to <${issueResult.issue.getCustomFieldValue(urgencyCustomField)}>")
          		} else {
          			(validationResult.errorCollection.errors.collect { "<${it.key}> field error: ${it.value}" } + 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.

Questions?

Ask us any time.