There is a script to copy a template project in workflow post-function, however it does not create a board.
The thread for copy a project is here: https://community.atlassian.com/t5/Answers-Developer-Questions/Call-built-in-script-from-workflow-post-function/qaq-p/566522
And here is the script:
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) : true, (CopyProject.FIELD_COPY_COMPONENTS) : true, (CopyProject.FIELD_COPY_ISSUES) : true, (CopyProject.FIELD_COPY_DASH_AND_FILTERS) : true, ] 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()
How to copy the board from the template project or how to create one for the new project?
I've found a solution here: https://community.atlassian.com/t5/Adaptavist-questions/Create-a-board-and-filter-with-custom-settings-using-script/qaq-p/634444
Code:
import com.atlassian.greenhopper.model.validation.ErrorCollection
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.web.rapid.view.RapidViewHelper
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.web.rapid.view.RapidViewResource.CreateResponse
import com.atlassian.greenhopper.web.rapid.view.RapidViewFilterHelper
import com.atlassian.greenhopper.web.rapid.view.RapidViewCreateModel
import com.atlassian.greenhopper.service.rapid.view.
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
RapidViewService rapidViewService
@JiraAgileBean
RapidViewHelper rapidViewHelper
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def errorCollection = new ErrorCollection()
// create a new board for project JRA
def projectIds = [ComponentAccessor.getProjectManager().getProjectObjByKey("ATP").id as String]
def outcome = rapidViewHelper.createRapidViewForPreset(currentUser, sourceIssue.summary + " Board", projectIds as Set, "scrum")
log.debug outcome
if (! outcome.isValid()) {
log.warn ("Failed to create board: ${outcome.errors}")
return
}
log.info ("Create board successfully.")
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
RapidViewService rapidViewService
@JiraAgileBean
RapidViewHelper rapidViewHelper
@ is considered as an error in script runner . Could I get any solution for that?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.