Scriptrunner CopyProject script does not work properly

Christos Moysiadis
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.
September 17, 2019
Thread executorThread = new Thread(new Runnable() {
void run() {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : "PR1",
(CopyProject.FIELD_TARGET_PROJECT) : "TEST",
(CopyProject.FIELD_TARGET_PROJECT_NAME) : "TST",
(CopyProject.FIELD_COPY_ISSUES) : true,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.error("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()

So i have a requirement lately about giving the ability to a limited group of users to copy a template project with the use of this script. Of course there are some more extensions behind it but they are not necessary to mention them currently. 

The current script can copy the project with the name and key correctly. Also the versions and the Components are copied too. I am straggling to find out why it doesn't copy the issues (Yes! the source project has iss.ues in it :P ). 

The jira-administrators group has 2 users . A default defined admin which i have from the install process which has all the permissions.

Jira instance is a pure fresh installed 8.3.2 version (i don't know if this creates the current problem.)

Any ideas my fellow Atlassians & Scriptrunner friends ???? Any workarounds maybe?

Regards

CM

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
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.
September 20, 2019

Does it work when you run the Copy Project Script from the ScrptRunner UI under Built-In Scripts?

Christos Moysiadis
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.
September 21, 2019

Basically yes. I even tried this script directly to the console and i have no results! :/

Peter-Dave Sheehan
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.
September 21, 2019

I tried your script (minus the executorThread) in my environment script console with a test project (contains 1 issue) and it worked.

Look in the Audit Log and see who the Author of the changes is. Then perhaps using the built-in script to change the active user to that user and try the built-in copy project script as that user. Are the issues copied?

If not, then look in the source project permissions scheme and make sure that your admin user has browse project and create issue permissions.

Like Christos Moysiadis likes this
Christos Moysiadis
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.
September 23, 2019

@Peter-Dave Sheehan the funny is that it now works. The even more funnier is that the template project Create Permission was assigned to "Any logged user" . I changed it to the admin user and it seems to work correct now. 

Thnx for your help! :)

Regards

0 votes
Gaurav Arora
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2021

Hi @Christos Moysiadis ,

A concrete solution for this is defined here, https://productsupport.adaptavist.com/browse/SRJIRA-3793

Best Regards,

Gaurav

TAGS
AUG Leaders

Atlassian Community Events