Add bulk release versions through script runner Edited

How to use scriptrunner scripts to add bulk release versions from a csv file for multiple projects or any other option to achieve it?

3 answers

1 accepted

Hi,

You could run a script like this in the Script Console:

import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey("CONFIG") // change project name here

def versionManager = ComponentAccessor.getVersionManager()

def versionList = ["CONFIG_18.01.01", "CONFIG_18.01.02", "CONFIG_18.01.03", "CONFIG_18.01.04",
"CONFIG_18.01.05", "CONFIG_18.02.01"]

for (version in versionList) {
log.debug("Now adding version " + version + " to " + project.name)
versionManager.createVersion(version, new Date(), new Date() + 7, "New version description", project.id, null)
}

For each project, you just need to change the project name on line 4. For versionList on line 7, you could just copy and paste the Fix Version/s from your Excel spreadsheet. 

After running the script in my instance:

Screen Shot 2017-12-07 at 10.46.25 AM.png

Please note the parameters used for createVersion on line 11. You will need to change the start/end date according to your specifications. See more about the createVersion method here.

Thanks Joshua for giving me the script snippet.

 

 

 


   

This works great, however I need to have different dates for each fixed version.  How would I alter it to include custom dates for each fixed version. 

Hi @Joshua Yamdogo [Adaptavist] Thanks much.

My requirement was to create more than 400 + versions across projects so had to tweak the scripts like below. Likewise , for different patterns I did update the contents inside createVersion( ).

Now for next release (year 2019) , I only need to change 18 to 19 :)

 

// Script to create version pattern <Project>_18.01.00 ,
// <Project>_18.01.02 ... <Project>_18.12.05 and so on

import com.atlassian.jira.component.ComponentAccessor

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

["PROJECT1","PROJECT2","PROJECT3","PROJECT4" ].each {  //Change project names here
def project = projectManager.getProjectObjByKey("${it}")

//loop to create version list

for(int i=0; i<=12; i++) {
    for(int j=1; j<=5; j++) {
        String secondStr ="";
        String thirdStr ="";
        if(i <10) {
            secondStr = "0"+i;
        } else {
            secondStr = i;
        }
        if(j <10) {
            thirdStr = "0"+j;
        } else {
            thirdStr = j;
        }
        versionManager.createVersion( "${it}"+"_18."+ secondStr + "." + thirdStr,null,null, "Release Description",project.id,null)
       }
    }
}

 

Hi @Joshua Yamdogo [Adaptavist] .

I utilized your script and made some more tweaks as my requirement was to create more than 400 + versions across projects . So wrote a scripts like below and made couple of more scripts to suit different version patterns.

Now for next activity ( year 2019 release) I only needed to change 18 to 19 on line 28  :)

 

 



























 

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

246 views 1 18
Join discussion

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