How to delete versions from Script

Jakeer May 15, 2023

Hello,

How to delete versions from Script?

Thanks,

1 answer

0 votes
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.
May 15, 2023

Welcome to the Atlassian Community!

What scripting function are you using?

Jakeer May 15, 2023

Hello, 

We are using Groovy scripting.

import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.getProjectManager()
def versionManager = ComponentAccessor.getVersionManager()

def project = projectManager.getProjectObjByKey("INT") //Change project key here for the project you want to change

//100p to create version list

for(int i = 170; 1<=220; i++) { //loop from which to which version you want to update variably
String secondstr = "3.1.28.0" +i; //add the fixed value here which won't change
versionManager.createVersion(secondstr,null,null, "",project.id,null)
}

 

Thanks,

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.
May 15, 2023

This is a script which adds versions.  What is the question about deleting them?

Pratish Korathu May 15, 2023

We are looking for script to bulk delete a series of project version.

Jakeer May 16, 2023

Hi @Nic Brough -Adaptavist- 

We have used below script for deleting the Versions, but it is showing Error

import com.atlassian.jira.project.version.Version
import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.getProjectManager()
def versionManager = ComponentAccessor.getVersionManager()

def project = projectManager.getProjectObjByKey("RPT") //Change project key here for the project you want to change
def versions = versionManager.getVersions(project)
log.warn(versions)
def noOfVersions=versions.size()
log.warn(noOfVersions)
for(def i="3.1.28.068765";i<="3.1.28.068769";i++) {
//String secondstr = "3.1.28.068" +i; //add the fixed value here which won't change
Version versionToDelete=versions[i]
versionManager.deleteVersion(versionToDelete)
}

Thanks,

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.
May 17, 2023

What are the errors you are getting?

I'd guess at the line with the loop on it being a problem - your def statement in there is defining i as a string, which you can't iterate over.

Suggest an answer

Log in or Sign up to answer