I'm wondering if there's a way to call one of the ScriptRunner built-in scripts (specifically, Copy Project) from inside a workflow post-function. The idea is, a user would be able to create an issue in a project that would ask for all the necessary information for the new project they would like to create, and then the workflow would perform any necessary validations/transformations and then create the new project. We have a "template" project that we like to copy from because it has all of our desired settings all ready to go, which is why I'd rather call the built-in "Copy Project" script as opposed to writing an entirely new script that creates a project, changes the settings, etc. Any ideas? (@Jamie Echlin [Adaptavist], I hate to bug you all the time, but you always know exactly what to do! )
It may be worth mentioning that we're using JIRA 6.4.11 and the free version of ScriptRunner.
Community moderators have prevented the ability to post new answers.
Never mind, I found another post where you had answered this, @Jamie Echlin [Adaptavist]. Here's what I'm using:
import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.canned.jira.admin.CopyProject import org.apache.log4j.Logger def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript") Thread executorThread = new Thread(new Runnable() { void run() { def copyProject = new CopyProject() def inputs = [ (CopyProject.FIELD_SOURCE_PROJECT) : 'SRCKEY', (CopyProject.FIELD_TARGET_PROJECT) : 'EX', (CopyProject.FIELD_TARGET_PROJECT_NAME) : "Example", (CopyProject.FIELD_COPY_VERSIONS) : false, (CopyProject.FIELD_COPY_COMPONENTS) : false, (CopyProject.FIELD_COPY_ISSUES) : false, (CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false, ] def errorCollection = copyProject.doValidate(inputs, false) if(errorCollection.hasAnyErrors()) { log.warn("Couldn't create project: $errorCollection") } else { def util = ComponentAccessor.getUserUtil() def adminsGroup = util.getGroupObject("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()
Yeah, that's the way to do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is there an updated version of this given the age and probably version changes? I would like to use this in a Post Function Still but not sure it is working for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.