##--------------------------------------------------------------------------- ## ## Copyright 2006 David Blevins ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. ## ##--------------------------------------------------------------------------- ## ## Swizzle script to export a JIRA project so it can be imported on ## on another JIRA instance. ## ## This script will connect via XML-RPC, RSS, and plain HTTP text/html ## ## It will also download the attachments to the /tmp directory. ## If you run this script on a different machine than where the ## destination JIRA instance is run, you will have to pack the ## attachments up, move them to the JIRA machine and unpack them ## into it's /tmp directory. ## ## This script required the following -D flags: ## ## username : the username to be used for XML-RPC authentication ## ## password : the password to be used for XML-RPC authentication ## ## projectKey : the JIRA key of the project to import from ## ## serverUrl : the base URL where jira is available, e.g. ## e.g. "http://jira.codehaus.org" or "http://issues.apache.org/jira" ## DO NOT put a slash on the end. ## ## These can be supplied as: ## ## java -jar swizzle-jirareport.jar jira-to-jira.xml -Dusername=joe -Dpassword=cool -DprojectKey=PEANUTS -DserverUrl=http://jira.acme.org ## ############################################################################# #set( $void = $params.required( "username" , "[a-zA-Z0-9]+", "the username to be used for XML-RPC authentication" ) ) #set( $void = $params.required( "password" , "[a-zA-Z0-9]+", "the password to be used for XML-RPC authentication" ) ) #set( $void = $params.required( "projectKey" , "[a-zA-Z0-9]+", "the JIRA key of the project to import from" ) ) #set( $void = $params.required( "serverUrl" , "https?://.+", "the base URL where jira is available, no trailing slash" ) ) #set( $void = $params.required( "jiraAdmin" , "[a-zA-Z0-9]+", "the username of the JIRA administrator doing the import" ) ) #set( $void = $params.validate() ) ## #set( $xml = $utils.load("org.codehaus.swizzle.jirareport.XmlUtil") ) #set( $att = $utils.load("org.codehaus.swizzle.jirareport.AttachmentsUtil") ) #set( $j = $utils.load("org.codehaus.swizzle.jirareport.JellyUtil") ) ## ## #set( $jira = $xmlrpc.connect("$username:$password","$serverUrl/rpc/xmlrpc") ) #set( $void = $jira.autofill("subtasks", true) ) #set( $void = $jira.autofill("attachments", true) ) #set( $void = $date.format("yyyy-MM-dd hh:mm:ss.0") ) ## #set( $project = $jira.getProject( $projectKey ) ) ## #set( $void = $att.createAttachmentsTmpDir($project) ) ## #set( $URL = "${serverUrl}/secure/IssueNavigator.jspa?view=rss&&pid=${project.id}&tempMax=100000&reset=true&decorator=none") #set( $jirarss = $rss.fetch( $URL ) ) #set( $issues = $jirarss.issues.sort("id") ) ## #set( $assignees = $issues.collect("assignee").unique("name").sort("name") ) #set( $unassigned = $assignees.equals("fullname", "Unassigned") ) #set( $assignees = $assignees.subtract($unassigned) ) ## #set( $users = $assignees.union($issues.collect("reporter")).unique("name").sort("name") ) ## #set( $lowkey = $strings.lc($project.key) ) #foreach( $user in $users ) #set( $user = $jira.getUser($user.name) ) #end #foreach( $user in $assignees ) #end #foreach( $component in $jira.getComponents($project.key) ) #end #foreach( $version in $jira.getVersions($project.key) ) #end #foreach( $issue in $issues ) #set( $issue = $jira.getIssue( $issue.key ) ) #if( $issue.type.id == 7 ) #set( $issue.type = $jira.getIssueType("Task") ) #end 0 ) components="$xml.escape($collections.join($issue.components, ","))" #end #if( $issue.affectsVersions.size() > 0 ) versions="$xml.escape($collections.join($issue.affectsVersions, ","))" #end #if( $issue.fixVersions.size() > 0 ) fixVersions="$xml.escape($collections.join($issue.fixVersions, ","))" #end #if( $issue.assignee ) assignee="$xml.escape($issue.assignee.name)" #else assignee="-1" #end reporter="$xml.escape($issue.reporter.name)" #if( $issue.environment ) environment="$xml.escape($issue.environment)" #end description="$xml.escape($issue.description)" duedate="$date.format($issue.duedate, "dd/MMM/yy" )" created="$date.format($issue.created)" updated="$date.format($issue.updated)" issueKeyVar="$j.keyRef($issue)" /> #end #set( $d = "$" ) #foreach( $issue in $issues.equals("status", "Closed") ) #end #foreach( $issue in $issues.equals("status", "Resolved") ) #end #foreach( $issue in $issues.equals("status", "In Progress") ) #end #foreach( $issue in $issues ) #foreach( $comment in $jira.getComments( $issue.key ) ) #end #end #foreach( $issue in $issues ) #set( $issue = $jira.getIssue( $issue.key ) ) select id from jiraissue where pkey = '${d}{$j.keyRef($issue)}' #end select id from issuetype where pname = 'Sub-task' select id from issuelinktype where linkname = 'jira_subtask_link' select SEQ_ID from SEQUENCE_VALUE_ITEM where SEQ_NAME='IssueLink' #foreach( $issue in $issues ) #set( $issue = $jira.getIssue( $issue.key ) ) #if( $issue.subTasks.size() > 0 ) #end #foreach( $subtask in $issue.subTasks ) #set( $sequence = $velocityCount - 1 ) update jiraissue set issuetype = ${d}{subtaskType} where id = ${d}{$j.idRef($subtask)} insert into issuelink values (${d}{primaryKey}, ${d}{subtaskLinkType}, ${d}{$j.idRef($issue)}, ${d}{$j.idRef($subtask)}, $sequence) #end update SEQUENCE_VALUE_ITEM set SEQ_ID=${d}{primaryKey} where SEQ_NAME='IssueLink' #end #foreach( $issue in $issues ) #set( $issue = $jira.getIssue( $issue.key ) ) #foreach( $attachment in $issue.attachments ) #if( $issue.reporter.fullname.equals($attachment.author) ) #set( $username = $issue.reporter.name ) #elseif( $issue.assignee.fullname.equals($attachment.author) ) #set( $username = $issue.assignee.name ) #else #set( $username = $collections.first($users.equals("fullname", $attachment.author)).name ) #end #set( $file = $att.saveAttachment($attachment)) select max(id) max from fileattachment where issueid = ${d}{$j.idRef($issue)} and filename = '$attachment.fileName' update fileattachment set author = '$username', created = '$date.format($attachment.created)' where id = ${d}{$j.idRef($attachment)} #end #end #foreach( $issue in $issues ) #set( $issue = $jira.getIssue( $issue.key ) ) update jiraissue set updated = '$date.format($issue.updated)' where pkey = '${d}{$j.keyRef($issue)}' #end #foreach( $issue in $issues.descending("id") ) #set( $issue = $jira.getIssue( $issue.key ) ) update jiraissue set pkey = '$issue.key' where id = '${d}{$j.idRef($issue)}' and pkey = '${d}{$j.keyRef($issue)}' #end