It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner create issue and link it Edited

I'm using a script available on BitBucket.

I need to add to this script the following:

I have project A with Workflow A, and an issue A

Running issue A, at certain point of WF A, i need to create a new project (B) with diferent WF (B)

The new project B, will have by default an Epic (with the same issue.summary of issue A).

I have already automated the creation of project B (based on a template project with no issues).

Allong this automation, i need to create the project B, and an epic B linked to Issue A

 

and thats it. no more links from that point on.

Can anyone help.

Tks

//Based on this example https://gist.github.com/jamieechlin/8240692

/*
  There is a problem with this script in scriptrunner versions around 5.5 onwards as the CopyProject class was changed.
  It clones the project but does not clone the issues
  
  I will update when I have found the solution
  
*/

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManager = ComponentAccessor.getProjectManager()

//These fields will need to be created as single line text fields so users can provide the new project key and project name
def destProjetKey = customFieldManager.getCustomFieldObjectsByName("New Project KEY")[0]
log.debug("New Project KEY: " + issue.getCustomFieldValue(destProjetKey))
def destProjectName = customFieldManager.getCustomFieldObjectsByName("New Project Name")[0]
log.debug("New Project Name: " + issue.getCustomFieldValue(destProjectName))

//change this to your template source project
def srcProjectKey = 'SSPA'
log.debug("Source Project Name: " + srcProjectKey)
def getSrcProjectObject = projectManager.getProjectByCurrentKey(srcProjectKey)
//Use getSrcProjectObject to check the source project exists

def targetKey = issue.getCustomFieldValue(destProjetKey)
def targetProjectName = issue.getCustomFieldValue(destProjectName)

if(getSrcProjectObject && targetKey && targetProjectName) {

    Thread executorThread = new Thread(new Runnable() {
        void run() {
            def copyProject = new CopyProject()
            def inputs = [
                (CopyProject.FIELD_SOURCE_PROJECT)       : srcProjectKey,
                (CopyProject.FIELD_TARGET_PROJECT)       : targetKey,
                (CopyProject.FIELD_TARGET_PROJECT_NAME)  : targetProjectName,
                (CopyProject.FIELD_COPY_VERSIONS)        : true,
                (CopyProject.FIELD_COPY_COMPONENTS)      : true,
                (CopyProject.FIELD_COPY_ISSUES)          : true,
                (CopyProject.FIELD_COPY_DASH_AND_FILTERS): false,
                //(CopyProject.FIELD_ORDER_BY)             : "Rank", <-- no longer a valid option so I am commenting this out
            ]

            def errorCollection = copyProject.doValidate(inputs, false)
            if (errorCollection.hasAnyErrors()) {
                log.warn("Couldn't create project: $errorCollection")
            } else {
                def util = ComponentAccessor.getUserUtil()
                def adminsGroup = ComponentAccessor.getGroupManager().getGroup("jira-administrators")
                assert adminsGroup // must have jira-administrators group defined
                def admins = util.getAllUsersInGroups([adminsGroup])
                assert admins // must have at least one admin

                ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
                copyProject.doScript(inputs)
            }
        }
    })

    executorThread.start()

}else{
    log.error("Cannot Clone Project as source Project, target key or target project names were Not found or Not specified")
}

 

 

1 answer

Hi Antonio

You are currently using that script to copy all issues from the source project.

(CopyProject.FIELD_COPY_ISSUES)          : true,

For Point 1:

  • I do not really understand what you mean here. Can you explain this further? It sounds like you are asking how to create a new issue that is not cloned from the source project, but I do not understand why you want to script this.

For Point 2:

  • Are you saying you want to link every issue you clone to the target project back to the original projects source issue?

 

Regards

Matthew

Hi Mattew,

bit messy my description. i try to simplify.

I have project A with Workflow A, and an issue A

Running issue A, at certain point of WF A, i need to create a new project (B) with diferent WF (B)

The new project B, will have by default an Epic (with the same issue.summary of issue A).

I have already automated the creation of project B (based on a template project with no issues).

Allong this automation, i need to create the project B, and an epic B linked to Issue A

 

and thats it. no more links from that point on.

 

hope this is clear than the previous description.

cheers

Antonio 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

How Unito's Newest Features Can Make Your Integrations Better

...ttachments another team sends over from Jira. Much easier for everyone involved. True sync for 100% of Trello native fields Trello is one of the most popular work management tools out there, and more Unito u...

177 views 0 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you