Hello Atlassian forum members,
Is it possible to add new users to JIRA using Groovy? I have looked through the UserManager and ApplicationUser but could not find anything related to new user creation. If anyone has experience with this and could assist, or could point me to the documentation should I have simply missed it I would appreciate it.
Thanks, and I hope this finds everyone doing well.
Regards,
Scott
Or if you decide to use Script Runner (and for JIRA v7.*) you can execute the script below to your script console
import com.atlassian.jira.bc.user.UserService import com.atlassian.jira.component.ComponentAccessor def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def userService = ComponentAccessor.getComponent(UserService) UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest. withUserDetails(user, "username", "password", "user@example.com", "Test User: user") UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest) if(result.isValid()) userService.createUser(result) else result.getErrorCollection()
For JIRA v6.*
import com.atlassian.jira.bc.user.UserService import com.atlassian.jira.component.ComponentAccessor def user = ComponentAccessor.getJiraAuthenticationContext().getUser() def userService = ComponentAccessor.getComponent(UserService) UserService.CreateUserValidationResult createUserValidationResult = userService.validateCreateUserForSetup( user.directoryUser, "username", "password", "password", "userName@example.com", "User Full Name") if(createUserValidationResult.isValid()) { def newUser = userService.createUserWithNotification(createUserValidationResult) return "User ${newUser.displayName} succesfully created" } else createUserValidationResult.getErrorCollection()
There are several methods you can call and create users with different rights see the UserService API, for example if you want a user with admin rights use
userService.validateCreateUserForAdmin(...)
and if you do not want to receive "user created" notifications use
userService.createUserWithNoNotification(...)
Two options always better than one....
I edited the params to make them more clear.
Kind regards
hi,
IT THROWS ERROR for me .
could you please provide the example in other format.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I improved the script above, let me know if this works for you. And if not please provide the error you get, if any, in the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi thanos,
Thanks .its working fine now ...
Great !!! I am looking answer for the past two days .i am searching for the groovy tutorials .But no luck ...
Good Job Thanos .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thanos,
i need a help from you ... i need to create a custom field with multi level cascading select . do u know about that .
i need to create 2 levels ,3 levels and 4 levels and also need to insert the n number of values in to that custom field at the time of the creation itself . it is possible in JIRA jelly runner . but in groovy i am not aware the process and the coding part too.
can you help on this ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could you please create a new question, because is different than the original one, and I am sure someone (or even me when I find some time) will answer.
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thanos,
already i created a new question in this blog .
fyr,
check this questions:
https://answers.atlassian.com/questions/38063913
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Thanos,
Thank you very much for your answer. We are still running JIRA 6.4.11 (something I should have stated in my question, apologies) but perhaps your suggestion can still work in the older API with some modification. I appreciate you taking the time to provide your thoughts, thank you again.
Regards,
Scott
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scott
Apologies for the confusion, I thought rTrack Support was you and I modified the original script to be compatible with JIRA7 (the original one was comp with JIRA 6.4), I will repost the JIRA6 compatible one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any confusion was my fault, not your I appreciate any help you are willing to provide, and thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added in the answer a script compatible with JIRA v6.* Please let me know if this works for you.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
addUser and related actions are available in the JIRA Command Line Interface (CLI) and can be used in almost any scripting language.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have seen some of the Bob Swift tools and they look quite powerful. Perhaps in the future we will have a chance to work with them. Thank you for your suggestion!
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.