Clones an Issue and Links
Use the Clones an issue, and links built-in post function to clone the current issue to a new one and create a link between the two. For example, when an issue is moved to With QA, we want the issue to be cloned to the QA project, and we want to update the summary of the cloned issue.
Post function configuration
Overriding field values
When using this post function 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 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.
When cloning an issue from one project to another, there may be times when a field is required in the target project but not required in the project of the issue being cloned, and therefore that field may be empty in the issue being cloned. In such a situation the issue is still cloned and the field will remain empty until you go into the target issue and edit it manually.
issue.summary = 'Cloned issue'
issue.setCustomFieldValue('My custom field name', 'value one')Control link cloning
When an issue is cloned, both outward and inward links are copied. If issue Adepends on issue B, after cloning to issue C, issue C will also depend on issue B. Similarly, if issue B was depended on by issue A, then issue B will also be depended on by issue C.
You can override this behavior and 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.
To disable the cloning of links altogether you can use the following code:
checkLink = {link -> false};To enable cloning of all links except links of the type Clones you can use the following code:
checkLink = {link -> link.issueLinkType.name != "Clones"}Control attachment cloning
When an issue is cloned, all attachments are also cloned. You can control which attachments are copied.
To disable attachment copying completely you can use the following code in the Additional issue actions field:
checkAttachment = {attachment -> false}To clone only the attachments added by the user alavigne you can use the following code in the Additional issue actions field:
checkAttachment = {attachment -> attachment.authorKey == 'alavigne'}After Create actions
Some actions can take place only after the issue is created (add watcher, create issue links, etc.). In this case, you can apply additional actions after the new issue is created using the doAfterCreate callback (closure).
For example, to add watchers to the new issue use the following code in the Additional issue actions field:
doAfterCreate = {
issue.addWatcher('anuser')
}You may want to link the new issue to another one. For example, to create a Duplicates issue link between the new issue and an issue with key SSPA-1 you can use the following code in the Additional issue actions field:
doAfterCreate = {
def issueToLinkTo = Issues.getByKey("SSPA-1")
issue.link('duplicates', issueToLinkTo)
}issueoutside the doAfterCreate closure is not yet created and trying to access it will result in an error—the issue.getKey() will throw a NullPointerException. On the other hand the issueinside the doAfterCreate callback is created and exists—therefore the issue.getKey() will return the key of the new issue.
Use this post function
You can now test to see if this post function works.