Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner CopyProject script does not work properly

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

0 votes
Answer accepted

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

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

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

@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

Hi @Christos Moysiadis ,

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

Best Regards,

Gaurav

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

779 views 17 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you