Hi,
i found some luck in creating user in JIRA using groovy runner .here i mention my code .can you pls tel me whether it is correct or need to modify .because it throws error while running the script .
code:
-----------
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userService = ComponentAccessor.getComponent(UserService)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserService.CreateUserValidationResult newValidUser =UserService.validateCreateUserForAdmin("p1247", "12025", "12025", "12025", "12025@ramco.com", "vijaya bhaskar v")
another code:
----------------
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userService = ComponentAccessor.getComponent(UserService)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserService.CreateUserValidationResult newValidUser =UserService.validateCreateUserForAdmin(currentUser, "12025", "12025", "12025", "12025@ramco.com", "vijaya bhaskar v")
error throws:
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.bc.user.UserService.validateCreateUserForAdmin() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) values: [P1247(p1247), 12025, 12025, 12025, 12025@ramco.com, vijaya bhaskar v] at Script250.run(Script250.groovy:6)
hi ,
I used that also . i found error with that .
code:
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userService = ComponentAccessor.getComponent(UserService)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
final CreateUserRequest createUserRequest = CreateUserRequest.withUserDetails("abc","abc", "abc", "abc@gmail.com", abc)
result = userService.validateCreateUser(createUserRequest);
if(result.isValid())
{
userService.createUser(createUserRequest);
}
error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script270.groovy: 7: unable to resolve class CreateUserRequest @ line 7, column 25. final CreateUserRequest createUserRequest = CreateUserRequest.withUserDetails("abc","abc", "abc", "abc@gmail.com", abc) ^ 1 error
It should be
UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest. withUserDetails(currentUser, "username", "password", "user@example.com", "Test User: user") UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Thanos ..
Its working fine now..
can you please guide me to learn groovy script for JIRA .can you provide any documents to learn groovy for JIRA .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Learning groovy (a programming language very similar to Java) is one thing and writing groovy-scripts (using SR) for JIRA is another. For the latter, SR documentation has a lot of example scripts and is a great starting point, and of course Atlassian Answers...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos ,
is there any possibility to map a new user into groups while creating the new user login .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
on top of my head, it should add something like that
if(result.isValid()) { def newUser = userService.createUser(result) def groupManager = ComponentAccessor.getGroupManager() def developersGroup = groupManager.getGroup("group-name") groupManager.addUserToGroup(newUser, developersGroup) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my code :
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, "ASDASDF", "AASDSDFA", "ASDASAFA@gmail.com", "ASDASAA")
UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest)
if(result.isValid())
{
def newUser = userService.createUser(result)
def groupManager = ComponentAccessor.getGroupManager()
def developersGroup = groupManager.getGroup("IMG USERS")
groupManager.addUserToGroup(newUser, developersGroup)
print newUser
print developersGroup
}
else
result.getErrorCollection()
note :it creates the user and also map to the group also .but in result tab shows as null .
how can i print the username
while creating the new user before it results with username .but now it shows as null while creating and mapping a new user to a group .
i used print statement also .but no luck in this .
can you help me to short out of it .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you should add
return newUser.getDisplayName()
just after the groupManager.addUserToGroup(newUser, developersGroup). Also notice that in order to get debug (or error, or info) messages in your logs the way is
log.debug("This is a debug message that will appear in you atlassian-jira.log file")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's deprecated Since v7.0. Use validateCreateUser(CreateUserRequest)
instead.
https://docs.atlassian.com/jira/latest/com/atlassian/jira/bc/user/UserService.html
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.