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.
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'
Issues.search('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"
return
}
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,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.