It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Bulk Clone Pro: How to clone entire Epic (with Issues and their Sub-Tasks)?

Hi - I'm evaluating Bulk Clone Professional, and need to clone our "template" Epic.  This Epic contains a handful of Tasks ("Issues in Epic").  Each of these Tasks in the Epic have a bunch of Sub-Tasks.  How do I clone this entire structure? When I clone this "template" Epic using Bulk Clone Professional, I only specify this single Epic as needing to be cloned, because I want to end up with a cloned Epic that contains the same (cloned) Tasks as the source Epic contains, and have each of these (cloned) Tasks point to (cloned) Sub-Tasks.

So in the pic attached, the 5 "Issues in Epic" would also be cloned, and listed in the cloned Epic's "Issues in Epic" section.  Also, I need each of the Sub-Tasks (of each Task) to also be cloned.  So a full Epic clone.

Thanks!

epic2clone2.jpg

4 answers

1 accepted

1 vote
Answer accepted

Ok, I figured it out.  Instead of assuming that just cloning the "top level" Epic, I need to use JQL (project = MIG and "Epic Link" = MIG-84 or issuekey  = MIG-84)  - where MIG-84 is the Epic - and clone the Epic and all of the "Issues in Epic" together.  Very cool plug-in.  

Where do you place the JQL?  The Backlog area is the only place you can multi-select (I think) and if I do a JQL search, I am taken to a Search results page where I cannot multi-select.

Hi Kristina - this is Fred, posting by mistake from my manager's account (oops ;_0 )  ... so I go to my project, and click on "view all issues and filters" in the upper right.  Make sure the "Advanced" link is clicked, and create a filter that selects the epic you want to clone - along with all of the tasks in that epic.  So for me, it's:

project = MIG AND "Epic Link" = MIG-84 OR issuekey = MIG-84 ORDER BY issuetype ASC, issuekey ASC

Then I save that filter.  When you're ready to clone that epic (with its tasks and task sub-tasks), run that filter (by going to your project, clicking on "view all issues and filters", and clicking on the filter you just saved).  

You'll now see the epics and tasks in that epic.  You won't see sub-tasks but they're cloned automatically with each task.  Now just follow the add-on instructions (go to tools -> bulk tools, change all X issues, and in bulk operations select all of them, click next, then select the add-on "clone issues", and you're off and running).

 

Logged in as myself (Fred) now - let me know if you have any other questions on this!

I was able to create JQL and see the list I wanted.  I don't see tools > bulk tools etc.  I'm trying to follow http://www.lbconsultinggroup.org/bulkclone-professional-documentation/ which recommends going to Backlog...I don't want that.

Couldn't see how to save the filter except to save it to a local file.

When you build up the filter (using either 'basic' or 'advanced'), there is a "Save As" button that you can click to save that filter.

We chose Bulk Clone Pro because we could clone Epics and their hierarchies across many different JIRA Projects.

Thanks for all of your help.  Our needs were simpler; may need this in the future though...

@Fred Lunau FYI - we ended up going with Jira Automation with a trigger on Epic creation to create all of the issues "below" the Epic.  It had more flexibility to create if/then scenarios for our agency model with multiple products plus the ability to suffix or prefix the issue names. I needed a coder to assist with the setup though.

Found out that we couldn't use the Epic cloning tool anymore because it would trigger Jira Automation.  Oops.  I'm sure there's a checkbox for that somewhere.

Hi,

I needed the same some time ago. I got a solution with 2 scriptrunner REST Endpoints called sequentially. The first is called from a custom web item (Script Fragments) in the more-menu of an issue. It shows a dialog where you can set the summary/epic name of the new epic. After clicking submit, the second endpoint is called.

Here are the scripts for the two REST Endpoints:

Dialog

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys

@BaseScript CustomEndpointDelegate delegate

showDialog() { MultivaluedMap queryParams ->
//get issueKey from parameters of REST Endpoint call
def issueKey = queryParams.getFirst("issueKey") as String
String BASE_URL = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);

//definition of Dialog with some Java Script
def dialog =
"""<script>
//On dialog the user can insert the summary/epic name of the new epic
//After clicking submit button, spinner is displayed and second REST Endpoint is called with new summary value
AJS.\$('[id="dialog-submit-button"]').click(function(){
var newSum = AJS.\$("#text-input").val()
if(newSum!=""){
AJS.\$("#text-input").parent().find(".error").hide()
var spinning = false;

if(!spinning){
AJS.\$(this).text('Cloning...');
AJS.\$('.button-spinner').spin();
spinning = true;
AJS.\$("#dialog-submit-button").attr("disabled",true)
}

var request = new XMLHttpRequest();
request.open("GET","${BASE_URL}/rest/scriptrunner/latest/custom/cloneEpicWithIssues?issueKey=${issueKey}&newSum="+newSum);
request.send();

//Keep the dialog open for 15s, then close it and reload the source epic
setTimeout(function(){
AJS.\$('#dialog-close-button').trigger('click');
function loadUrl(newLocation){
window.location.href = newLocation;
};
loadUrl('${BASE_URL}/browse/${issueKey}');
},15000);
}else{
//show error message if field for new summary is empty
AJS.\$("#text-input").next().append('<div class="error">Summary for new Epic is required</div>')
}
});
</script>

//Dialog definition, got from scriptrunner documentation and adapted
<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main">Clone Epic with Issues in Epic</h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
</a>
</header>

<div class="aui-dialog2-content">
<p>Please insert Summary of new Epic</p>
<form class="aui">
<div class="field-group">
<label for="text-input">New Epic Name<span class="aui-icon icon-required">required</span></label>
<input class="text" type="text" id="text-input" name="text-input" title="summary">
<div class="description">Please insert Name of new Epic</div>
</div>
</form>
</div>

<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="dialog-submit-button" class="aui-button aui-button-primary">Submit</button>
<span style="padding-left: 15px; padding-bottom: 10px; display: inline-block;" class="button-spinner"></span>
<button id="dialog-close-button" class="aui-button aui-button-link">Cancel</button>
</div>
</footer>
</section>
"""

//Show dialog
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

Clone Epic:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.user.UserManager
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.Response
import org.apache.log4j.Category
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.config.properties.APKeys
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import java.sql.Timestamp;
import org.apache.log4j.Logger;

@BaseScript CustomEndpointDelegate delegate

cloneEpicWithIssues(httpMethod: "GET") { MultivaluedMap queryParams,body, HttpServletRequest request ->

// Variable definition
def issueKey = queryParams.getFirst("issueKey") as String // issuekey from request parameters
def newSummary = queryParams.getFirst("newSum") as String // newSummary value from request parameters
def epic_link_field="customfield_12739";
def epic_name_field="customfield_12738";
def issueMgr = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def issueFactory = ComponentAccessor.getIssueFactory()
Issue issue = issueMgr.getIssueObject(issueKey)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Timestamp Ts = new Timestamp(System.currentTimeMillis());
CustomField epicLink = customFieldManager.getCustomFieldObject(epic_link_field);
CustomField epicName = customFieldManager.getCustomFieldObject(epic_name_field);

//Get current issues in epic -> links from and to source epic
List<IssueLink> outwardLinks = linkMgr.getOutwardLinks(issue.getId())
List<IssueLink> inwardLinks = linkMgr.getInwardLinks(issue.getId())
List<Issue> outwardLinkedIssues = [] as List<Issue>;
List<Issue> inwardLinkedIssues = [] as List<Issue>;

outwardLinks.each{
outwardLinkedIssues.add(it.getDestinationObject())
}

inwardLinks.each{
inwardLinkedIssues.add(it.getSourceObject())
}

//sorting of epic links - not neccessary, was requirement from users
outwardLinkedIssues.sort{a,b -> a.getId()<=>b.getId()}
outwardLinkedIssues = outwardLinkedIssues.reverse()

inwardLinkedIssues.sort{a,b -> a.getId()<=>b.getId()}
inwardLinkedIssues = inwardLinkedIssues.reverse();

ModifiedValue mVal;

MutableIssue clonedIssue;
MutableIssue clonedEpic;

try {
//Clone epic with all fields
def toClone = issueFactory.cloneIssueWithAllFields(issue)
clonedEpic = issueMgr.createIssueObject(issue.reporter, toClone) as MutableIssue

//set current system time as created date, otherwise it would have created date from source epic
//issue.store() is deprecated but issueManager.updateIssue didn't work, don't know why
clonedEpic.setCreated(Ts)
clonedEpic.store();

//Set new summary and epic name (same in this case)
clonedEpic.setSummary(newSummary)
clonedEpic.store();

mVal = new ModifiedValue(clonedEpic.getCustomFieldValue(epicName), newSummary);
epicName.updateValue(null, clonedEpic, mVal, new DefaultIssueChangeHolder());

//if source epic has outward links, clone each linked issue and set epic link to new epic
//For sub-tasks, this is unfortunately not working. Therefore they are excluded
if(!outwardLinks.isEmpty()){
outwardLinkedIssues.each{
if(it.issueType.name!="Sub-task"){
toClone=issueFactory.cloneIssueWithAllFields(it)
clonedIssue = issueMgr.createIssueObject(issue.reporter, toClone) as MutableIssue

clonedIssue.setCreated(Ts)
clonedIssue.store();

mVal = new ModifiedValue(clonedIssue.getCustomFieldValue(epicLink), clonedEpic);
epicLink.updateValue(null, clonedIssue, mVal, new DefaultIssueChangeHolder());
}
}
}

if(!inwardLinks.isEmpty()){
inwardLinkedIssues.each{
if(it.issueType.name!="Sub-task"){
toClone=issueFactory.cloneIssueWithAllFields(it)
clonedIssue = issueMgr.createIssueObject(issue.reporter, toClone) as MutableIssue

clonedIssue.setCreated(Ts)
clonedIssue.store();

mVal = new ModifiedValue(clonedIssue.getCustomFieldValue(epicLink), clonedEpic);
epicLink.updateValue(null, clonedIssue, mVal, new DefaultIssueChangeHolder());
}
}
}
}catch(e){
return Response.serverError().entity([error: e.message]).build();
}

String BASE_URL = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);

//show success message and load new epic - doesn't work in some cases, don't know why
String clonedMessage = """
Navigating to created issue <a href="${BASE_URL}/browse/${clonedEpic.getKey()}">${clonedEpic.getKey()}</a>...
<script>
function loadUrl(newLocation){
window.location.href = newLocation;
};
loadUrl('${BASE_URL}/browse/${clonedEpic.getKey()}');
</script>
"""
UserMessageUtil.success(clonedMessage)
}

 Maybe not the best solution, but it is working for us. At least useful as a workaround until Atlassian maybe is providing such a function in the standard JIRA application in the future.

Hello,

Can you please share the Custom Web Item configuration?

Hello,

Getting below error while executing this code. Could you please help me in fixing this?

2019-01-25 10:36:38,866 ERROR [common.UserCustomScriptEndpoint]: *************************************************************************************
2019-01-25 10:36:38,873 ERROR [common.UserCustomScriptEndpoint]: Script endpoint failed on method: GET cloneEpicWithIssues
java.lang.NullPointerException: Cannot invoke method getId() on null object
 at Script5$_run_closure1.doCall(Script5.groovy:48)
 at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:375)
 at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:256)

Hi,

here is a screenshot of the web item configuration.

I think you get the error message as you didn't provide the issue. In the configuration you do that in the "Link" field.

 

2019-01-31_13h36_37.png

Hello Jonas,

Thanks for your reply.

I configured in the same way. But the issue is not created. Could you please help me with this? Is this something related to condition?

SF.PNG

Hi,

do you have a REST Endpoint configured that is called "showDialog"? It is called in the URL with the issue as parameter. It is defined in the first code snippet above. This dialog calls the second Endpoint if you click on "Submit" so it is necessary for this to work that both Endpoint exist.

Yes and No error though. When I click on Submit it is redirected to the same source issue and when I search for new epic, unable to find.RE.PNG

So, the log files don't show anything?

Then you maybe can add a logger to log some information on the issue creation or the new issue.

Folks, if you have the latest version of the JIRA CLI installed (I have Atlassian CLI 8.0.0), then this command below will clone everything listed below:

  • the EPIC,
  • the issues under the EPIC,
  • the sub-tasks under the EPIC,
  • the sub-tasks under the issues under the EPIC,
  • as well as any other linked JIRA tasks 

jira --action cloneIssues --jql "project=ABC and 'Epic Link' = ABC-123 or IssueKey = ABC-123" --copySubtasks --copyLinks

Hello,

Can you please share the custom web item configurations?

Hi Fred

But is the EPIC-Link also changed?

JQL: key = TEST-1756 OR "EPIC Link"= TEST-1756 ORDER BY issuetype ASC

The issues in the list are from different projects.

Then I do the Clone and select all the issues.

I select the following issues in the 3rd step:

  • Clone Subtasks
  • Clone Issue Links
  • Rebuild Issue Links
  • Rebuild Epic Link

Everything looks fine - except the Epic Link. This is still to the old Epic.

Yes, I noticed that that is the behavior for non-admins. When I ran it as an admin it copied the links correctly into the new EPIC. This is a serious detraction of the cloning tool, IMO.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 03, 2019 in Marketplace Apps

How to estimate projects more accurately?

Gaining insight into your team’s effectiveness and choosing the right estimation technique.   Estimating projects is hard. It is because people have the tendency to underestimate the time thin...

278 views 2 8
Read article

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