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

How do I copy all issues inside a project to another project via ScriptRunner?

Igor Zhigalkin March 19, 2024

ScriptRunner has an built-in script that allows to clone existing project, which copy all instances (issues, schemes, etc.). 
I need an option to copy only issues (in perfect scenario found by custom JQL search). 

My usual routine is:

1. Create a project from a template

2. Copy (clone and move) all issues from "dull" project (issues are stages, epics and tasks) to a new one.


I want to automate step 2, which takes enormous amount of time and manual efforts.

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 20, 2024

Hi @Igor Zhigalkin

For your requirement, I suggest trying something like this:-

import com.adaptavist.hapi.jira.issues.Issues
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def projectKey = 'EX''project = MOCK').each {
def issueToCopy = Issues.getByKey(it.key)
def blockIntraprojectLinks = '{l -> l.sourceObject.projectObject != l.destinationObject.projectObject}'

if (!issueToCopy) {
log.warn "Issue ${issueToCopy.key} does not exist"

def inputs = [
(CloneIssue.FIELD_TARGET_PROJECT) : projectKey,
(CloneIssue.FIELD_LINK_TYPE) : null,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): ["checkLink = $blockIntraprojectLinks;", ""],
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
(CloneIssue.SKIP_EPIC_LINKS) : "false",
] as Map<String, Object>

def executionContext = [issue: issueToCopy] as Map<String, Object>

def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)
def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)

assert updatedExecutionContext.newIssue

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

This code has been extracted from the Adaptavist Library and modified slightly with the ScriptRunner HAPI feature for simplification.

With the sample working code above, I can copy all the issues in the MOCK project to the Example, i.e. EX project.

Below is a screenshot of the code in the ScriptRunner Console:-


I hope this helps to solve your question. :-)

Thank you and Kind regards,



Igor Zhigalkin March 20, 2024

Thank you very much, this code worked perfectly!

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events