Missed Team ’24? Catch up on announcements here.

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

Jira REST Api Clone an Issue

manicresin January 16, 2013

Is it possible to clone an issue using the REST api?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2013

Not yet. You can probably write a new REST method in a plugin!

manicresin January 17, 2013

That is what I started doing, should be fun!

Like h likes this
avnish mishra July 19, 2016

@Kyle Wilson Are you able to do it?

1 vote
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2013
manicresin January 17, 2013

Yes I saw that, but its cloneIssue action used the companion plugin. Looks like creating a REST module to give me the option through the API shouldnt be too difficult and get me going on plugin development.

Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2013

The clone action only requires the Clone Plus Plugin for JIRA if you try to use any of the functions that are not supported by the standard clone operation. So, just cloning an issue without setting fields or changing the project/issues will just use the normal clone action.

0 votes
c00lmat February 19, 2018

With Adaptavist Scriptrunner installed you can define a script endpoint without writing a plugin.

Ours clones custom fields and has some parameters you might want to use or not (coworkerIds). You will easily strip out useless parts of the code below if needed.

// CLONE

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import static com.atlassian.jira.component.ComponentAccessor.*

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
    
@BaseScript CustomEndpointDelegate delegate

clone(httpMethod: "GET") { MultivaluedMap queryParams ->

    String issueKey = queryParams.getFirst("issueKey") as String
    String assigneeId = queryParams.getFirst("assigneeId") as String
    String coworkerIds = queryParams.getFirst("coworkerIds") as String
    String summary = queryParams.getFirst("summary") as String
    def issue = issueManager.getIssueObject(issueKey)

    
    def clonedIssue = issueFactory.cloneIssue(issue)
    if(summary) clonedIssue.summary = summary
    if(assigneeId) clonedIssue.assigneeId = assigneeId
    
    if(coworkerIds) {
        clonedIssue.setCustomFieldValue(
            customFieldManager.getCustomFieldObjectByName("Co-Workers"),
            coworkerIds.split('[,\\s]+').collect { userManager.getUserByName(it) }
        )
    }

    customFieldManager.getCustomFieldObjects( issue.projectObject.id, issue.issueTypeObject.id).each {
        def value = it.getValue(issue)
        if(value) clonedIssue.setCustomFieldValue(it, value)
    }

    def createdIssue = issueManager.createIssueObject(jiraAuthenticationContext.user, clonedIssue)
    
    def builder = new groovy.json.JsonBuilder()
    builder { key createdIssue.key }
    return Response.status(201).entity(builder.toString()).build()
}
Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

Why does queryParams.size() =1 ...

Even with ?issuekey=TEST-479&summary=newClone&fdfsdf=dsfdsf&sdfsdf=sd

Like Maksim Koriukin likes this
TAGS
AUG Leaders

Atlassian Community Events