Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to fetch versions (version name,startdate,releasedate) details by using projectID

TesterAnees November 24, 2016

Hi Team,

I have couple of versions in my project.

I need to fetch startdate and release date of versions and do some calculations on it.

image2016-11-25 14:52:57.png

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.version.VersionManager

 

def projectKey = issue.getProjectId() //this will give me project_id

i need to fetch versions startdate,versions releasedate by passing project_id.

-----------------

I have done some R&D on how to achieve this,

getAllVersions() //this will give me all the versions present in system

Date getReleaseDate() it will give release date of version

Date getStartDate() it will give start date of version

Reference:https://docs.atlassian.com/jira/server/com/atlassian/jira/project/version/Version.html#getStartDate--

https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/project/ProjectManager.html

 

I am new to groovy,can any one please help me with pseudo code to achieve this.

 

Thanks in advance,

 

 

 

 

 

 

 

 

2 answers

0 votes
TesterAnees November 30, 2016

Thank you Shamith Shankar smile

I do have another question, i have stored my project's version's startdate in a array list. Now i wanted to sort that list and fetch "Nearest date,smallest date,largest date" 

 image2016-12-1 12:47:8.png

I want 1-oct-2016 and 29-jun-2015

 

 

My code:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import java.util.*

projectCount = new ProjectCount(issues)//creating object for this classs

public class ProjectCount {
def issues
def versions
def versionStart
public ProjectCount(issues) {
this.issues = issues

calMetr1(this.issues)
}

public def calMetr1(issues){
versionStart = new ArrayList<Date>()
def project = issues.get(0).getProjectObject()
// get the versions for this project
this.versions = project.getVersions() 
//i am storing version startDate in arraylist,my project can contains null vales also
for(version in versions)
{
versionStart.add(version.getStartDate())

}
// i want to sort my list and pick the nearest date from it and display it(though VM template)

//i have tried using versionStart.sort(),versionStart.last() but no luck sad
}
}

 

can you please help me with this 

 

Thanks in advance

TesterAnees November 30, 2016

versionStart.max(),versionStart.min() worked.

Do we have any other way

0 votes
Shamith Shankar
Contributor
November 24, 2016
 
 
Project p =ComponentAccessor.getProjectManager().getProjectObj("long");
Collection&lt;Version&gt; versions=p.getVersions();
for(Version v:versions){
    v.getReleaseDate()
    v.getStartDate()
}

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events