Clones an Issue and Links

Use this built-in post function to clone the current issue to a new one and create a link between the two.

You can specify the following options:

  • Which fields are being copied—either all fields, no fields, or specific fields from the source issue to the new one.
  • Whether you want to copy comments, organizations and subtasks.
  • The user the newly cloned issue is created on behalf of (As User field). This affects the creator and the reporter of the newly cloned issue. If empty, the currently logged-in user is used.
  • The target issue type and target project. If you leave them blank the clone has the same project and type as the cloner.
  • The link type and direction. This is typically Clones but it doesn’t have to be.

Overriding field values

If you want to override some field values rather than have them inherited from the source issue, you can specify that in the Additional issue actions field. For example, the following snippet sets the summary field and a custom field called MyCustomFieldType to "my value":

issue.summary = 'Cloned issue' issue.setCustomFieldValue('My custom field name', "my value")

Both outward and inward links are copied. So if issue A depends on issue B, after cloning to issue C then issue C will also depend on issue B. And similarly if issue B was depended on by issue A.

You can override this behavior to copy links selectively or disable it altogether by providing a callback (a closure) called checkLink in the Additional issue actions field. The callback will be called for every link found and should return true or false. This is passed by one parameter, the IssueLink object. For example, to disable the cloning of links altogether use this code:

checkLink = {link -> false};

To enable cloning of all links except links of the type Clones use:

checkLink = {link -> link.issueLinkType.name != "Clones"}

Control of cloning attachments

In a similar way, you can control which attachments are copied. To disable attachment copying completely:

checkAttachment = {attachment -> false}

To clone only the attachments added by the user jbloggs:

checkAttachment = {attachment -> attachment.authorKey == 'jbloggs'}

This post-function should be placed immediately after the function: Re-index an issue to keep indexes in sync with the database. If you don't do this, the parent issue is not indexed correctly.

After Create actions

There are some actions that can take place only after the creation of the issue (add watcher, create issue links etc), in this case you can apply additional actions after the creation of the new issue, using the doAfterCreate callback (closure).

For example, add watchers to the new issue:

doAfterCreate = {
    issue.addWatcher('anuser')
}

Another use of it could be, linking the new issue to another one. For example, create a 'duplicates' issue link between the new issue and an issue with key JRA-24:

doAfterCreate = {
    def issueToLinkTo = Issues.getByKey("SSPA-1")

    issue.link('duplicates', issueToLinkTo)
}

The variable issue outside the doAfterCreate closure is not yet created and trying to access it will result to an error (the issue.getKey() will throw a NullPointerException). On the other hand the issue inside the doAfterCreate callback is created and exists (therefore the issue.getKey() will return the key of the new issue).

On this page