Call built-in script from workflow post-function

Jordan Packer March 9, 2016

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! smile)

It may be worth mentioning that we're using JIRA 6.4.11 and the free version of ScriptRunner.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Jordan Packer March 9, 2016

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()
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2016

Yeah, that's the way to do it.

Cary Watkins August 19, 2019

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. 

TAGS
AUG Leaders

Atlassian Community Events