Does ScriptRunner help to find projects with unused FixVersions

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

This widget could not be displayed.

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.

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

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é 

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.

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

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

Comment is obsolete.

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

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)

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

510 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you