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

Script Runner: Copy workflows and associate with a new project



I have a workflow scheme that serves as a template. It holds workflow templates.

When I create a new project, I'd like to copy the template workflows to the new project scheme. 

Is there a script someone can share?




3 answers

1 accepted

0 votes
Answer accepted

Thanks @Derek_Fields  I've figured it out.

For anyone else that might need this code, here it is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project


def workflowManager = ComponentAccessor.workflowManager
def schemeManager = ComponentAccessor.workflowSchemeManager
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager
def issueTypeScheme = ComponentAccessor.issueTypeSchemeManager
def userManager = ComponentAccessor.userManager


//Create a project objects (Source & Target)
Project jiraProjectSourceObj = projectManager.getProjectObjByName("YOUR SOURCE PROJECT")
Project jiraProjectTargetObj = projectManager.getProjectObjByName("YOUR TARGET PROJECT")

//Create a user object
// need to figure out how to get the current user!
def adminUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//defining Workflow Scheme
def newWorkflowSchemeGenericObj
def newWorkflowSchemeObj
def newWorkflowSchemeName
def newWorkflowSchemeDescription

// Create Workflows properties
def newWorkflowName = ""
def newWorkflowDescription = "To be used with this project"
def sourceWorkflowName
def jiraWorkflowObj
def jiraWorkflowCloneObj

//Create a issue type scheme object

def sb = new StringBuffer()

//Creating a Workflow Scheme Object
newWorkflowSchemeName = jiraProjectTargetObj.key +" Workflow Scheme"
newWorkflowSchemeDescription = "To be used only in " +jiraProjectTargetObj.key+ " project"
newWorkflowSchemeObj = schemeManager.createSchemeObject(newWorkflowSchemeName, newWorkflowSchemeDescription)


sourceWorkflowName = schemeManager.getWorkflowSchemeObj(jiraProjectSourceObj).getActualWorkflow(
jiraWorkflowObj = workflowManager.getWorkflow(sourceWorkflowName)

//adjusting the name of the workflow to suit our naming convention
newWorkflowName ="Template", jiraProjectTargetObj.key)
jiraWorkflowCloneObj = workflowManager.copyWorkflow(adminUser, newWorkflowName, newWorkflowDescription, jiraWorkflowObj)

//Converting the Scheme Object to a Generic Object so that I can add the workflows to the scheme
newWorkflowSchemeGenericObj = schemeManager.getScheme(

newWorkflowName = ""

//Switching Workflow Schemes
schemeManager.addSchemeToProject(jiraProjectTargetObj, newWorkflowSchemeObj)



catch(Exception e) {
sb.append(" || Error: " + e + "\n");

return sb.toString()

0 votes
Derek_Fields Community Leader Jan 07, 2020

Why not just use the "Create with Shared Confiuration" option in the Project Creation screen? That will copy all of the schemes associated with the template project to the new project. 

Hi @Derek_Fields ,


I'd like each project to have their own workflow instance. So that each delivery team can make changes to their flow without any impact on the other delivery team.





Derek_Fields Community Leader Jan 07, 2020

Creating such a script isn't that difficult, but it is fair amount of work. For me, it would take about 2-3 hours to write and test. Maybe someone else can do it faster.

Suggest an answer

Log in or Sign up to answer

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