Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

How to use the Groovy Script Runner to create user.

Takashi Hattori June 9, 2016

Hello team

I would like to use groovy script runner to "create user" and "add User to Group". Please tell me how to write groovy script "create users" and "add user to group".

Do you have any sample groovy script? Thanks.

3 answers

1 accepted

2 votes
Answer accepted
Boris Georgiev [Appfire]
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.
June 9, 2016

Code for creating a user

ComponentAccessor.getUserUtil().createUserNoNotification(username, "",
emailAddress, displayName, null);

And for adding user to group you can use com.atlassian.jira.user.util.UserUtil.addUserToGroup(Group, User)

Takashi Hattori June 9, 2016

Georgiev-san Thank you very much for your information.

 

Code for creating a user -> I succeeded.

>import com.atlassian.jira.component.ComponentAccessor

>def userUtil = ComponentAccessor.getUserUtil()

>userUtil.createUserNoNotification("TEST MAN1111","","TESTMAN@TEST.com","TEST MAN1")

 

I try to use UserUtil.addUserToGroup of JIRA api but adding user to group failed.

>import com.atlassian.jira.component.ComponentAccessor

>def userUtil = ComponentAccessor.getUserUtil()

>userUtil.addUserToGroup("gr_Admin","TEST MAN1111")

 

errormessage:

>No signature of method: com.atlassian.jira.user.util.UserUtilImpl.addUserToGroup() is

>applicable for argument types: (java.lang.String, java.lang.String)

>values: [gr_Admin, TEST MAN1111] Possible

>solutions: addUserToGroup(com.atlassian.crowd.embedded.api.Group, com.atlassian.crowd.embedded.api.User),

>addUserToGroups(java.util.Collection, com.atlassian.crowd.embedded.api.User)

 

I am sorry to cause you inconvenience, but I am looking forward to your reply.

Best Regards,

Takashi

Boris Georgiev [Appfire]
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.
June 9, 2016

Hi Hattori-san,

here's the full code for adding user to group

import com.atlassian.jira.component.ComponentAccessor;
def uu = ComponentAccessor.getUserUtil()
def user = uu.getUserByName("boris.georgiev")
def group = uu.getGroupObject("jira-developers")
uu.addUserToGroup(group, user.getDirectoryUser())
Like Datta likes this
Takashi Hattori June 9, 2016

Georgiev-san

Thank you very much.

It was able to be settled!!

Best Regards, Takashi

Boris Georgiev [Appfire]
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.
June 9, 2016

Would you please mark the answer as accepted ? Thanks

it-service-frankfurt November 27, 2016

Hi Boris,

would it be possible to extend this script to create multiple new users, each one with multiple group memberships?

I am looking to replace an older Jelly script which will probably not work from JIRA 7 upwards.

Thanks in advance

Detlev

0 votes
Michael Aglas
Contributor
December 3, 2020

deprecated

0 votes
Takashi Hattori June 12, 2016

Georgiev-san

I am sorry for the delay in my reply.

Yes,Thank you very much. I was able to handle it.

Best Regards,

Takashi

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events