Hi everyone,
Jira Version : 7.9.2
ScriptRunner : 5.4.12
I have a post-function custom groovy script which i try to start synchronization of crowd directory. But when transition is over (post-function seems to be working), synchronization of directory didn't starts. Here's the weird part. If i run the same code at the script-runner console ; synchronization starts and finished. (I check the jira user directory page to see sync is started or not.)
import com.atlassian.crowd.embedded.api.CrowdDirectoryService
import com.atlassian.crowd.embedded.api.Directory
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
def className = "tr.com.foo.Scripts.sync_crowd"
def Logger log = Logger.getLogger(className)
log.debug("Script " + className + " started")
try{
CrowdDirectoryService crowdDirectoryService = ComponentAccessor.getComponent(CrowdDirectoryService.class);
if (crowdDirectoryService != null){
List<Directory> directories = crowdDirectoryService.findAllDirectories();
for (Directory directory : directories){
if (directory.getType().name().equals("CROWD")){
if (crowdDirectoryService.isDirectorySynchronisable(directory.getId())){
crowdDirectoryService.synchroniseDirectory(directory.getId());
log.debug(directory.getId() + " in sync")
}
}
}
}
else{
log.debug ("Directories not found")
}
} catch (Exception e){
log.debug("exception: " + e)
}
This code doesn't work when it is used as a post-function but works if i run it from the script runner console.
What could be the reason for this ?
I know it's 5 years late, but I got the same issue and managed to resolved it. I used different class, but it should work also with above example. There are two functions to synchronize user directories. Use the one with parameter for "run in background" set to false and it starts to work in postfunction. Mine code is like this:
I am having the same issue - did you ever find the solution?
I tried setting the user with @PD Sheehan 's example above, but that did not work either.
My transition is being initiated by Automation For Jira, and the "actor" is the same admin account that is able to do this with no problem in the scriptrunner console.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't have a way to verify, but I wonder if it might be a permission issue.
In the console, you are obviously an admin.
But in the post-function, you might expect a non-admin user to kick that off. I guess if you perform the workflow function instead of a non-admin user... does it work? Or does it not work regardless of the user?
Either way, maybe you try to change the current user before executing that part of the script with:
def adminUser = ComponentAccessor.userManager.getUserByName('admin')
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(adminUser)
Are any of the logs message found when running as post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.