Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner Clone project on transition - problem with issues

Wojtek Miecznikowski
January 21, 2019

Hi,

 

I trying prepare self service to creating JIRA projects. Now in JIRA working project clone, but just without issues - everythink looks good, but i last case i need copy Issues from source project. I trying a lot things with code like below :

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.atlassian.jira.issue.Issue
//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 = 'ASAP'
def srcProjectKey = 'SPP'
def destProjectName = 'ASAP'

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) : destProjetKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : 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()

and without result. Code working fine in "Run Script" from Add-ons level, but from transition leve Issues is not able to copy (with error NullPointerException. In atlassian-jira I receiving:


2019-01-21 11:36:23,529 ajp-nio-8009-exec-2 ERROR 696x12002x1 1kbyjsn /secure/WorkflowUIDispatcher.jspa [c.o.s.c.jira.utils.AbstractCloneIssue] Failed to create issue
com.atlassian.jira.exception.CreateException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Expected one match for [Expr::id::=::15123] but found 0: []

and:

2019-01-21 11:36:23,544 ajp-nio-8009-exec-2 ERROR  696x12002x1 1kbyjsn /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SS-105, actionId: 111, file: <inline script>
java.lang.NullPointerException

 

I tried:

- remove any validators

- every place in post function 

- use 2 type of post funcions: JMWE groovy script and scriptu runner script

- allow everything for my user in permission scheme

- change executingadmin

but still everything working fine from Add-ons level, but not working from transition level.

 

 JIRA 7.10.2

ScriptRunner 5.4.47

 

 

Anyone have any idea? I will be grateful for any advise.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Alex Christensen
Community Champion
November 28, 2018

I was able to figure this out. The syntax inside the pathsMatch() function should not include the repo name as part of the path name. In my first example above, I just shouldn't have included "repo" in the path name.

I also realized that the reviewer is added to the "Reviewers" field before the PR is actually created, not after, so that was helpful in troubleshooting. I was also trying to add myself as a reviewer to my own PRs, but you can't add yourself as a reviewer on your own PRs, so that was another issue. :)

M Bleyer
February 3, 2023

I am trying to do the same thing, what was the exact code you used in the end?

 

E.g. this also worked for me:

event.pullRequest.pathsMatch("glob:**substring_in_pathname**")
TAGS
AUG Leaders

Atlassian Community Events