Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update the latest release version automatically for SW Bug.

Raju July 19, 2024

Hello Community,

We have some projects and all are using same kind of release there is a version synchronizer for that one i mean if any version created or released in program(Parent) level project it will automatically  come in team(child projects).

My issue whenever the version release which matches with some pattern it will automatically update in this JQL 

issuetype = "SW Bug" AND affectedVersion in versionMatch("MP1_A00*") AND status not in (Closed,"REVIEW VERIFICATION@AS","In Verification@Stakeholder")

for this i wrote listener script 


 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.project.VersionReleaseEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.project.version.Version

if (event instanceof VersionReleaseEvent) {
    def version = event.getVersion()
    def project = version.getProject()
    def versionPattern = /\bMP1_A00[a-zA-Z0-9_]*\b/

    if (version.name ==~ versionPattern) {
        def issueManager = ComponentAccessor.getIssueManager()
        def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
        def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
        def jqlQuery = 'issuetype = "SW Bug" AND affectedVersion in versionMatch("MP1_A00*") AND status not in (Closed, "REVIEW VERIFICATION@AS", "In Verification@Stakeholder")'
        def query = jqlQueryParser.parseQuery(jqlQuery)
        def searchService = ComponentAccessor.getComponent(SearchService)
        def searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

        searchResults.results.each { issue ->
            def mutableIssue = issueManager.getIssueObject(issue.id) as MutableIssue
            def currentVersions = new HashSet<Version>(mutableIssue.getAffectedVersions())

            if (!currentVersions.contains(version)) {
                currentVersions.add(version)
                mutableIssue.setAffectedVersions(new ArrayList<Version>(currentVersions))

                // Logging for testing
                log.warn "Updating issue ${mutableIssue.key} with version ${version.name}"

                issueManager.updateIssue(user, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
               
                // Ensure issue is correctly updated and indexed
                def issueIndexingService = ComponentAccessor.getComponentOfType(com.atlassian.jira.issue.index.IssueIndexingService)
                issueIndexingService.reIndex(mutableIssue)
            }
        }
    }
}
it is updating the latest version in the Affects Version/s field but the exact issue is if i am trying to edit the Affects Version/s field the version is no longer available.

Could you please help me out.

Thanks in Advance!

1 answer

0 votes
Raju July 19, 2024

Hello,

If automation rule also fine for this one.

Thank you!

Suggest an answer

Log in or Sign up to answer