Hi Team,
whats the wrong in versionManager.archiveVersion(version, true) ....
tempList.each{ version ->
def version_releaseDate = version.getReleaseDate()
def released = version.isReleased()
if (released && version_releaseDate.toString() <= preYear)
{
versionManager.archiveVersion(version, true)
}
}
getting below error...
Hi @Yogesh Mude,
Looks like the passed parameter type is not suitable for the method used
it should be archiveVersion(Version version, boolean archive)
Can you pass me your complete code to have a quick look
BR,
Leo
Hello @Leo
thanks for the response.
below is the complete code...
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.VersionManager
import java.text.SimpleDateFormat
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("MTV")
def versions = ComponentAccessor.getVersionManager().getVersions(project)
def filteredVersions = []
versions.each { version ->
if(version.getReleaseDate() != null ){
filteredVersions.add(version)
}
}
def uniqueNamesList = []
for(int i=0; i<filteredVersions.size(); i++){
if(!(uniqueNamesList.contains(filteredVersions[i].toString().substring(0, filteredVersions[i].toString().lastIndexOf("-"))))){
uniqueNamesList.add(filteredVersions[i].toString().substring(0, filteredVersions[i].toString().lastIndexOf("-")))
}
}
log.error " Component Count ${uniqueNamesList.size()} " + " Component Name : ${uniqueNamesList}"
uniqueNamesList.each { componentName ->
def tempList = []
filteredVersions.each { version ->
if(version.toString().substring(0, version.toString().lastIndexOf("-")) == componentName)
{
tempList.add(version)
}
}
//log.error " Version count in each component : ${tempList.size()} " + " Name : ${tempList}"
//Run the archiving code over tempList
ArchiveVersions(tempList)
}
def ArchiveVersions(def tempList){
VersionManager versionManager = ComponentAccessor.getVersionManager()
// def result = ""
def count = 0
def bundledVersions = 0
def lastDate
Calendar cal = Calendar.getInstance()
cal.add(Calendar.YEAR, -2)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
def preYear = sdf.format(cal.getTime()) //2018-04-21
tempList.sort{it.getReleaseDate()}
for(int i = tempList.size()-1; i>=0; i--)
{
if(lastDate == null){
count++
}
else if (lastDate == tempList[i].getReleaseDate()){
count++
}
else if (lastDate != tempList[i].getReleaseDate() && bundledVersions ==0){
bundledVersions++
count++
}
else if (lastDate != tempList[i].getReleaseDate() && bundledVersions ==1){
i = -1
}
lastDate = tempList[i].getReleaseDate()
}
def whileIndex = 1
def filteredVersionsSize = tempList.size()
while(whileIndex <= count){
int final_index = filteredVersionsSize - whileIndex
tempList.remove(final_index)
whileIndex++
}
tempList.each{ version ->
def version_releaseDate = version.getReleaseDate()
def released = version.isReleased()
if (released && version_releaseDate.toString() <= preYear)
{
versionManager.archiveVersion(version, true)
}
}
log.error "Total version archived count ${tempList.size()}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try below code, I just adjusted data type on the fields you used to store version nothing else
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.project.version.Version
import java.text.SimpleDateFormat
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("MTV")
def versions = ComponentAccessor.getVersionManager().getVersions(project)
List<Version> filteredVersions
versions.each { version ->
if(version.getReleaseDate() != null ){
filteredVersions.add(version)
}
}
def uniqueNamesList = []
for(int i=0; i<filteredVersions.size(); i++){
if(!(uniqueNamesList.contains(filteredVersions[i].toString().substring(0, filteredVersions[i].toString().lastIndexOf("-"))))){
uniqueNamesList.add(filteredVersions[i].toString().substring(0, filteredVersions[i].toString().lastIndexOf("-")))
}
}
log.error " Component Count ${uniqueNamesList.size()} " + " Component Name : ${uniqueNamesList}"
uniqueNamesList.each { componentName ->
def temList = []
filteredVersions.each { version ->
if(version.toString().substring(0, version.toString().lastIndexOf("-")) == componentName)
{
temList.add(version)
}
}
//log.error " Version count in each component : ${tempList.size()} " + " Name : ${tempList}"
//Run the archiving code over tempList
ArchiveVersions(temList)
}
def ArchiveVersions(temList){
VersionManager versionManager = ComponentAccessor.getVersionManager()
List<Version> tempList = temList as List
tempList.sort{it.getReleaseDate()}
// def result = ""
def count = 0
def bundledVersions = 0
def lastDate
Calendar cal = Calendar.getInstance()
cal.add(Calendar.YEAR, -2)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
def preYear = sdf.format(cal.getTime()) //2018-04-21
for(int i = tempList.size()-1; i>=0; i--)
{
if(lastDate == null){
count++
}
else if (lastDate == tempList[i].getReleaseDate()){
count++
}
else if (lastDate != tempList[i].getReleaseDate() && bundledVersions ==0){
bundledVersions++
count++
}
else if (lastDate != tempList[i].getReleaseDate() && bundledVersions ==1){
i = -1
}
lastDate = tempList[i].getReleaseDate()
}
def whileIndex = 1
def filteredVersionsSize = tempList.size()
while(whileIndex <= count){
int final_index = filteredVersionsSize - whileIndex
tempList.remove(final_index)
whileIndex++
}
tempList.each{ version ->
def version_releaseDate = version.getReleaseDate()
def released = version.isReleased()
if (released && version_releaseDate.toString() <= preYear)
{
versionManager.archiveVersion(version, true)
}
}
log.error "Total version archived count ${tempList.size()}"
}
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On the below line i got the error saying can not invoke add method on the null object so i changed it to the previous one and works fine.
List<Version> filteredVersions
Thanks for your quick response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.