Hi
Is it possible to create (or copy) a project on workflow post function?
I see there is Built in script for this action, but how can I use it in workflow.
My idea is create simple workflow that selects specific project template (created before) and copy this template to new project. Unfortunately I didn't find any info about it. Is it possible?
Thanks,
Fyodor
Hi Fyodor,
I haven't ever actually tried this, and I don't necessarily recommend running this script as a post-function, but you should be able to get the actual content of the script by clicking ''view source'' after having selected the script in the builtin script field.
Put the copied script into your WEB-INF/classes/com/onresolve/jira/groovy/canned/workflow/postfunctions folder and change the
package com.onresolve.jira.groovy.canned.admin
for
package com.onresolve.jira.groovy.canned.workflow.postfunctions
Might require some hacking around but it's a start, depending on how familiar you are with groovy coding:
You can find a bit more info on how this would work here:https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Workflowfunctions-Post-functions
You can use this post-function to do this: https://gist.github.com/jamieechlin/8240692
Obviously various params would be replaced by custom field values etc.
You could copy the source, but I don't really recommend it - multiple maintenance problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
thanks for this snippet. Is there an actual version because I was not able to resolve import of packages.
Best regards
Christof
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christof,
I believe you will be having issues with the import of the CopyProject class. Try changing:
import com.onresolve.jira.groovy.canned.admin.CopyProject
to:
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I already use this class.
This is my code:
package examples
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import com.onresolve.jira.groovy.user.FieldBehaviours
//import com.onresolve.jira.groovy.user.FormField
import org.apache.log4j.Logger
import org.apache.log4j.Level
Logger.getLogger("com.onresolve").setLevel(Level.DEBUG)
def log = Logger.getLogger("com.onresolve.jira.groovy.MyCopyProjectScript")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def destProjetKey = customFieldManager.getCustomFieldObjectByName("New Project KEY")
log.debug("New Project KEY: " + issue.getCustomFieldValue(destProjetKey))
def destProjectName = customFieldManager.getCustomFieldObjectByName("New Project Name")
log.debug("New Project Name: " + issue.getCustomFieldValue(destProjectName))
def srcProjectKey = 'TEMPKAMP'
log.debug("Source Project Name: " + srcProjectKey)
Thread executorThread = new Thread(new Runnable() {
void run() {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : srcProjectKey,
(CopyProject.FIELD_TARGET_PROJECT) : issue.getCustomFieldValue(destProjetKey),
(CopyProject.FIELD_TARGET_PROJECT_NAME) : issue.getCustomFieldValue(destProjectName),
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
//(CopyProject.FIELD_COPY_GREENHOPPER) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
(CopyProject.FIELD_ORDER_BY) : "Rank",
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.warn("Couldn't create project: " + errorCollection)
}
else {
def util = ComponentAccessor.getUserUtil()
def adminsGroup = ComponentAccessor.getGroupManager().getGroup("jira-administrators")
assert adminsGroup // must have jira-administrators group defined
def admins = util.getAllUsersInGroups([adminsGroup])
assert admins // must have at least one admin
def executingAdmin = ComponentAccessor.getUserManager().getUserByName(admins.first().name)
log.debug("Executing Admin: " + executingAdmin.getName())
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(executingAdmin)
copyProject.doScript(inputs)
}
}
})
executorThread.run()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all
Thank you for advices, I will try scenarios you offered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use the CLI Plugin for JIRA and it's JIRA post function to run cloneProject, createProject, or similar actions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fyodor,
I haven't ever actually tried this, and I don't necessarily recommend running this script as a post-function, but you should be able to get the actual content of the script by clicking ''view source'' after having selected the script in the builtin script field.
Put the copied script into your WEB-INF/classes/com/onresolve/jira/groovy/canned/workflow/postfunctions folder and change the
package com.onresolve.jira.groovy.canned.admin
for
package com.onresolve.jira.groovy.canned.workflow.postfunctions
Might require some hacking around but it's a start, depending on how familiar you are with groovy coding:
You can find a bit more info on how this would work here:https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Workflowfunctions-Post-functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline 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.