Hi,
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?
Cheers,
Guy
Thanks @Derek Fields _RightStar_ 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()
try{
//Creating a Workflow Scheme Object
newWorkflowSchemeName = jiraProjectTargetObj.key +" Workflow Scheme"
newWorkflowSchemeDescription = "To be used only in " +jiraProjectTargetObj.key+ " project"
newWorkflowSchemeObj = schemeManager.createSchemeObject(newWorkflowSchemeName, newWorkflowSchemeDescription)
issueTypeScheme.getIssueTypesForProject(jiraProjectSourceObj).each{
sourceWorkflowName = schemeManager.getWorkflowSchemeObj(jiraProjectSourceObj).getActualWorkflow(it.id)
jiraWorkflowObj = workflowManager.getWorkflow(sourceWorkflowName)
//adjusting the name of the workflow to suit our naming convention
newWorkflowName = jiraWorkflowObj.name.replaceAll("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(newWorkflowSchemeObj.id)
schemeManager.addWorkflowToScheme(newWorkflowSchemeGenericObj, jiraWorkflowCloneObj.name, it.id)
newWorkflowName = ""
}
//Switching Workflow Schemes
schemeManager.removeSchemesFromProject(jiraProjectTargetObj)
schemeManager.addSchemeToProject(jiraProjectTargetObj, newWorkflowSchemeObj)
}
catch(Exception e) {
//noop
sb.append(" || Error: " + e + "\n");
}
return sb.toString()
works great.
if you dont want to create new workflows then you can just comment out following lines:
//adjusting the name of the workflow to suit our naming convention
newWorkflowName = jiraWorkflowObj.name.replaceAll("Template", jiraProjectTargetObj.key)
jiraWorkflowCloneObj = workflowManager.copyWorkflow(adminUser, newWorkflowName, newWorkflowDescription, jiraWorkflowObj)
and then use this line:
schemeManager.addWorkflowToScheme(newWorkflowSchemeGenericObj, jiraWorkflowObj.name, it.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guy, I have to say - THANK YOU!
This has helped me immeasurably.
Again, thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do they have this working for Jira Cloud yet? I see other threads about it only for Jira Server, but they were last year. Specifically for Service Desk...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello good work,
I'm searching this to create a complete Project for duplicating all scheme and objects (Screen, Fieds Customisation...) from a template project.
I try your script and I got this answer when i try :
|| Error: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.workflow.DefaultWorkflowSchemeManager.addWorkflowToScheme() is applicable for argument types: (com.atlassian.jira.scheme.Scheme, String, String) values: [Scheme{id=10205, type=WorkflowScheme, name=TESDUP_WS, description=To be used only in TESDUP project, entities=[0]}, ...] Possible solutions: addWorkflowToScheme(org.ofbiz.core.entity.GenericValue, java.lang.String, java.lang.String
It seems to not appreciate this : schemeManager.addWorkflowToScheme(newWorkflowSchemeGenericObj, jiraWorkflowCloneObj.name, it.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have modified the script to create a new workflow schema and a workflow cloned from SOURCE PROJECT, and assign WF/WFS to the TARGET PROJECT while removing the default WF/WFS of the TARGET.
It still assigning the WF for each issue type.
Jira 9.12.15/Scriptrunner 8.42.0
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("SOURCE PROJECT") Project jiraProjectTargetObj = projectManager.getProjectObjByName("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 // A - added a static string value for newWorkflowName here def newWorkflowName = "New Workflow by Scriptrunner" def newWorkflowDescription = "To be used with this project" def sourceWorkflowName def jiraWorkflowObj def jiraWorkflowCloneObj //Create a issue type scheme object def sb = new StringBuffer() try{ //Creating a Workflow Scheme Object newWorkflowSchemeName = jiraProjectTargetObj.key +" Workflow Scheme Created by Scriptrunner" newWorkflowSchemeDescription = "To be used only in " +jiraProjectTargetObj.key+ " project" newWorkflowSchemeObj = schemeManager.createSchemeObject(newWorkflowSchemeName, newWorkflowSchemeDescription) issueTypeScheme.getIssueTypesForProject(jiraProjectSourceObj).each{ sourceWorkflowName = schemeManager.getWorkflowSchemeObj(jiraProjectSourceObj).getActualWorkflow(it.id) jiraWorkflowObj = workflowManager.getWorkflow(sourceWorkflowName) //adjusting the name of the workflow to suit our naming convention // A - commented out below line // newWorkflowName = jiraWorkflowObj.name.replaceAll("Template", jiraProjectTargetObj.key) jiraWorkflowCloneObj = workflowManager.copyWorkflow(adminUser, newWorkflowName, newWorkflowDescription, jiraWorkflowObj) newWorkflowSchemeGenericObj = schemeManager.getScheme(newWorkflowSchemeObj.id) schemeManager.addWorkflowToScheme(newWorkflowSchemeGenericObj, jiraWorkflowCloneObj.name, it.id) // A - commented out below line to avoid resetting newWorkflowName, every time the copyWorkflow works it finds the previously created workflow and updates it. //newWorkflowName = "" } //Switching Workflow Schemes schemeManager.removeSchemesFromProject(jiraProjectTargetObj) schemeManager.addSchemeToProject(jiraProjectTargetObj, newWorkflowSchemeObj) } catch(Exception e) { //noop sb.append(" || Error: " + e + "\n"); }
I am sharing as an example and as is, you can modify it for your needs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Derek Fields _RightStar_ ,
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.
Cheers,
Guy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create with Shared Confiuration make configuration shared, instead of copy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In our Jira design, we wanted to provide Jira projects with the flexibility to modify it for their own needs. But I needed a starting point to set up a project.
When you copy/clone a workflow, any changes you make are dedicated to its Jira project and don't impact others.
With shared configuration, that doesn't work. Every change you make to the workflow will be reflected in other projects that will use the workflow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.