Does ScriptRunner help to find projects with unused FixVersions

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2017

With JIRA JQL I can search for all FixVersions, but I cannot find the projects for unused FixVersions, even they are show in the pulldown list.

Does ScriptRunner support it? Would be great to have the code prepared for usage in the ScriptRunner console.

Reason: There are sometime spelling mistakes, like "Release 1.0 " (a space at the end) and more. 

Using the Audit Log I can search for "Project version created" and the version name, but this was not so efficient.

 

 

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2017

As a search function, no.  Because a search is a search for issues, so you'd never find any because the version is not used.

But in the console, you could write a script to get a list of versions from a project, run a short search for any issues for each one, then report on the ones that return 0.

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2017

Hey @Jose M_

What Nick said. 

So try the following script in your script console 

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.versionManager
def issueManager = ComponentAccessor.issueManager
def project = ComponentAccessor.projectManager.getProjectObjByKey("TAT")

def fixVersionsInUse = issueManager.getIssueIdsForProject(project.id)?.collect { issueManager.getIssueObject(it) }?.collect {it.fixVersions}?.flatten()

def result = []
result.addAll(versionManager.getVersions(project))
result.removeAll(fixVersionsInUse)

def projectUrl = projectVersionConfigURL(project.key)
"<h3>Verions that are not used as FixVersions for Project $projectUrl </h3> ${result?.join("<br>")}"


static String projectVersionConfigURL (String projectKey) {
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
"""
<a href="$baseUrl/plugins/servlet/project-config/$projectKey/administer-versions">$projectKey</a>
"""
}

This is for one project, but you can easily extend it to be for all the projects... 

regards, Thanos

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2017

Thanks a lot, Thanos! I will try.

Is it also possible to search for all projects in a specific category? 

Or can I find out in which project a wrong and empty version, whose name I know, is used? Can I search that wrong version and find the project? 

Thanks for any help. 

Regards,

José 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2017

If you wrap Thanos' code in another loop, then yes.

Use

def projectList = projectManager.getProjectsFromProjectCategory( projectManager.getProjectCategoryObjectByName("My category") )

To get a list of projects to run over, then you can iterate through projectList for each project and run Thanos' code within it.

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2017

Thanks, @Nic Brough -Adaptavist-, but by using
def projectList = projectManager.getProjectsFromProjectCategory( projectManager.getProjectCategoryObjectByName("My category") )

with an existing category I got the message:

Error

No such property: projectManager for class: Script29

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2017

Thanks, @Thanos Batagiannis _Adaptavist_, your script works fine!

Just one thing: The result includes the URL ..../plugins/servlet/project-config/.../administer-versions, but at least in our JIRA 7.1.10 the URL is without administer, just /versions

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2017

Comment is obsolete.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 21, 2017

Have you created the projectManager like the issueManager and versionManager in Thanos' code?

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2017

I guess so:

 import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.versionManager
def issueManager = ComponentAccessor.issueManager
def project = ComponentAccessor.projectManager.getProjectObjByKey("...")
def projectList = projectManager.getProjectsFromProjectCategory( projectManager.getProjectCategoryObjectByName("...") )

def fixVersionsInUse = issueManager.getIssueIdsForProject(project.id)?.collect { issueManager.getIssueObject(it) }?.collect {it.fixVersions}?.flatten()

def result = []
result.addAll(versionManager.getVersions(project))
result.removeAll(fixVersionsInUse)

def projectUrl = projectVersionConfigURL(project.key)
"<h3>Verions that are not used as FixVersions for  Project $projectUrl </h3> ${result?.join("<br>")}"


static String projectVersionConfigURL (String projectKey) {
    def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
    """
    <a href="$baseUrl/plugins/servlet/project-config/$projectKey/administer-versions">$projectKey</a>
    """
}

groovy.lang.MissingPropertyException: No such property: projectManager for class: Script101
at Script101.run(Script101.groovy:6)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 21, 2017

There's no projectManager get in there - look at the second line, you need to do the same thing, but create the projectManager object. 

Also, you could then, if you felt like it, simplify the def project  and projectList lines down.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events