Hello,
we are facing some issues with Clone Project functionality provided by ScriptRunner. We use the following code to copy project in Post Function:
Thread executorThread = new Thread(new Runnable() {
void run() {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : sourceProjectKey,
(CopyProject.FIELD_TARGET_PROJECT) : projectKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : projectName,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
(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()
The project we are cloning contains issues, which we want to clone as well. The problem is that as the result, we receive empty project without any issues in it. Evidently, the clone function ends properly because logs do not contain any exception.
I checked permissions on source project and it seems to be alright (set to “jira-administrators”). I also checked audit records and everything seems to be ok (the project is created under admin).
Now the weird part: it works when I call it manually from build-in scripts and it even works when I call exactly the same script from Scriptrunner console. I found similar issues as ours, but nothing resolved the problem:
I will be very grateful for any ideas.