Automatically update the latest release version to the issue

Raju May 15, 2024

Hello community,

I wrote one listner script but I am getting error could you please help me out where I am getting error.

 

import com.atlassian.jira.component.ComponentAccessor

// Get necessary Jira components
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

// Define the issue type and affected versions field
def issueTypeToCheck = "sw bug"
def affectedVersionsFieldName = "Affected Versions"

// Retrieve the issue
def issue = event.issue

// Check if the issue type is "sw bug"
if (issue.issueType.name == issueTypeToCheck) {
// Get the affected versions field
def affectedVersionsField = customFieldManager.getCustomFieldObjects(issue).find { it.name == affectedVersionsFieldName }

// Get the current affected versions
def currentAffectedVersions = issue.getCustomFieldValue(affectedVersionsField) ?: []

// Get the latest release version
def latestReleaseVersion = issue.fixVersions.last()?.name

// Check if the latest release version matches the pattern MP1_A00**
if (latestReleaseVersion && latestReleaseVersion =~ /^MP1_A00/) {
// Add the latest release version to affected versions if it's not already there
if (!currentAffectedVersions.contains(latestReleaseVersion)) {
currentAffectedVersions.add(latestReleaseVersion)
issue.setCustomFieldValue(affectedVersionsField, currentAffectedVersions)
}
} else if (latestReleaseVersion == "MP1_S00") {
// Do nothing if the latest release version is MP1_S00
}
}

 

Thanks in advance.

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 17, 2024

Hello @Raju 

What error are you getting?

Suggest an answer

Log in or Sign up to answer