Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create bulk users in jira from csv file.

Salwadi Edukondal October 3, 2020

Hi Team,

 I have written groovy code like below but getting errors can anyone help me how to rectify this.

import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.UserService.CreateUserRequest
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript

 

File file = new File("C:/Users/edukondal.salwadi/Desktop/file.csv")
def csvMapList = []

file.eachLine { line ->
def columns = line.split(",")
def tmpMap = [:]

tmpMap.putAt("userName", columns[0])
tmpMap.putAt("userEmail", columns[1])
tmpMap.putAt("userFullName", columns[2])
csvMapList.add(tmpMap)
}

return csvMapList

 

Error:Getting below even though i have given correct path 

java.io.FileNotFoundException: C:\Users\edukondal.salwadi\Desktop\file.csv (The system cannot find the path specified) at Script5775.run(Script5775.groovy:31)

2 answers

0 votes
Ismael Jimoh
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.
October 3, 2020

Hi @Salwadi Edukondal 

Why not use Rest API to create the users?

You can use a csv with all information about users:

  1. Build your CSV with the basic information required by JIRA (username, name, email) see: https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/user
  2. Build a collection based on this.
  3. Run the collection to create the users.

This makes it easier.

Regards

Srikanth Ganipisetty
Contributor
August 15, 2021

@Ismael Jimoh Did you mean to write a REST API Script that can check mapping from this CSV file and doing post method hitting our Instance directly? Sorry, I am not much into Code. 

Ismael Jimoh
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.
August 15, 2021

You do not need a special script as I mentioned build a collection (please look up building collection in postman).

You can pass environment information like url, username, password that you store in Postman.

Anyway read or watch a video that explains using collection in postman and how to manage environments.

Like • Srikanth Ganipisetty likes this
Srikanth Ganipisetty
Contributor
August 16, 2021

@Ismael Jimoh Yeah, I know how to use collections in postman. Of course, we have the script to add the user and check the user status against AD and then put the user in relevant group. But, I thought using the methods you shared above from Atlassian is only helping to add 1 user, not the bulk users right? Correct me if I wrong. I thought that we can post JSON in the REST API methods above for user by user only. 

 

Thanks,

Srikanth Ganipisetty.  

Ismael Jimoh
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.
August 16, 2021

@Srikanth Ganipisetty you mentioned you have the users in a csv file from my understanding.

The point of a collection is to run till it gets to the end of a file.

So if you upload your file with the list of users to be added to the collection, the collection keeps running creating your users you have listed in the file to the application.

This is no different that say you are creating users in the database, when you run the prepared queries, yes it will bulk create the entries, however inn reality, it is still running them line by line or user by user.

There is no way you can in one command create 2 users without parsing them iteratively.

Like • Srikanth Ganipisetty likes this
Srikanth Ganipisetty
Contributor
August 17, 2021

Gotcha! @Ismael Jimoh I will try adding this CSV file to the collection. 

0 votes
Niranjan
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.
October 3, 2020

Hi ,

You may be running into this issue - https://productsupport.adaptavist.com/browse/SRJIRA-2330?

Ensure that directory name has no spaces. You can copy and paste the exact path by doing a dir of that file in the command prompt. Seems like a permission issue to me. Try to use the path for which jira has all the permissions.

Salwadi Edukondal October 4, 2020

I have checked everything looks fine path and permissions.

Can you check any change required in code?

Suggest an answer

Log in or Sign up to answer