How to get all users of JIRA with a Groovy script?

Mark Lovelady June 22, 2017

Hi,

I'm trying to put a script together to get a list of all users (cloud version), script/error below. Can anyone offer any guidance with this?

Thanks!

Mark

Script:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserUtil UserUtil userUtil = ComponentAccessor.getUserUtil() result = ” userUtil.getUsers().each{ u -> result += u.emailAddress } result
Error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class com.atlassian.jira.user.util.UserUtil
@ line 2, column 1.
import com.atlassian.jira.user.util.UserUtil
^

Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor
@ line 1, column 1.
import com.atlassian.jira.component.ComponentAccessor
^

2 errors

at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:41)
at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:28)
at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$1.callCurrent(Unknown Source)
at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:26)
at ScriptExecution1_groovyProxy.run(Unknown Source)

 

 

5 answers

1 vote
Srini Chimata August 31, 2022

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

UserUtil userUtil = ComponentAccessor.getUserUtil()

def result = ""

userUtil.getUsers().each{ u ->
result += u.username + "<br>"
}

result

Shay Keidar November 29, 2022

Thank you very much.

1 vote
Gaston Valente
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.
July 11, 2017

Hi, this code is correct and works, but your version works too.

  • Which version of Jira are you using?
  • Are you running this from the script console?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

UserUtil userUtil = ComponentAccessor.getUserUtil()

def result = ""

userUtil.getUsers().each{ u ->
result += u.emailAddress
}

result
Rene Asanga November 18, 2019

Could this be modified to output users and number them so I can get a count of total users.

Michael Aglas May 22, 2020

userUtil.getUsers() is deprecated, just saying

0 votes
Vid Kraner December 20, 2023

A bit late to the party, so I am sure you already figured it out.
Basically, all suggested scripts are for the Server/Data Center version.
Check the documentation: ScriptRunner Cloud Documentation 

But for all who come to this question, the Cloud version of ScriptRunner doesn't use the "import" anymore. 
And if you come to this question searching for Cloud solution for all users. I am sorry, but the API call to "Get all users" is not supported:
https://community.developer.atlassian.com/t/scriptrunner-get-all-users/71956 

 

0 votes
L Chaptal March 27, 2019

Is it possible to add last connexion date ?

I need the same... anyone who knows the answer?
Thanks...

Like Dave Liao likes this
0 votes
Stephen Hayden
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.
September 25, 2018

could this be modified to output users per project?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events