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

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)

 

 

1 answer

0 vote
Gaston Valente Community Champion Jul 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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

260 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you