Created
December 21, 2011 17:33
-
-
Save xhanin/1506888 to your computer and use it in GitHub Desktop.
A groovy script to batch update fixVersions in JIRA. Very slow but does the job. Use at your own risk!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This groovy script is used to bulk update fixVersions in JIRA. | |
It uses a filter listing all issues in the project (to remove the version), | |
and a filter to which the fixVersion should be added. | |
INSTALLATION: | |
1) download and unzip atlassian cli: | |
https://studio.plugins.atlassian.com/wiki/display/ACLI/Atlassian+Command+Line+Interface | |
2) modify the jira.sh to include the server, your user name and password (as documented in the jira.sh) | |
3) set then env variable ATLASSIAN_CLI_HOME to the dir where atlassian cli is unzipped | |
RUN: | |
arguments: | |
- first is the filter returning all issues in project, | |
- second is the filter returning the issues to be marked with version, | |
- third is the version to mark | |
*/ | |
@Grapes( | |
@Grab(group='com.xlson.groovycsv', module='groovycsv', version='0.2') | |
) | |
import com.xlson.groovycsv.CsvParser | |
def jiraCli = System.getenv()['ATLASSIAN_CLI_HOME'] + '/jira.sh' | |
def projectFilter = args[0] | |
def filter = args[1] | |
def rpt = args[2] | |
// utility methods | |
def removeVersion = { issue, version -> | |
println "checking $issue.Key for $version" | |
def fixVersions = issue['Fix Versions'].tokenize(',')*.find("'([^']+)'", {match, v -> return v}) | |
if (fixVersions.contains(version)) { | |
println "removing $version from $issue.Key" | |
def upFixVersions = fixVersions.minus(version).join(',') | |
def cmd = [jiraCli, "--action", "updateIssue", "--issue", "${issue.Key}", "--fixVersions", "$upFixVersions"] | |
println cmd | |
def p = cmd.execute() | |
p.waitFor() | |
println p.in.text | |
if (p.exitValue()) println "ERR[${p.exitValue()}] $p.err.text" | |
} | |
} | |
def addVersion = { issue, version -> | |
println "adding $version to $issue.Key" | |
def cmd = """${jiraCli} --action updateIssue --issue ${issue.Key} --fixVersions $version --append""" | |
println cmd | |
def p = cmd.execute() | |
p.waitFor() | |
println p.in.text | |
if (p.exitValue()) println "ERR[${p.exitValue()}] $p.err.text" | |
} | |
def findIssues = { f -> | |
def proc = """${jiraCli} --action getIssueList --filter $f""".execute() | |
proc.waitFor() | |
csv = proc.in.text.readLines()[1..-1].join('\n') | |
def data = new CsvParser().parse(csv, separator: ',', quoteChar: '"') | |
return data | |
} | |
// body | |
println "cleaning all project issues" | |
findIssues(projectFilter).each { issue -> removeVersion(issue, rpt) } | |
println "\n\n\nadding version to matching issues" | |
findIssues(filter).each { issue -> addVersion(issue, rpt) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment