Hi team
Im trying to add users from csv file , i find a code i added some line , connection with csv it's ok also adding user it's okay , but always it add only the user number 1 . other list no .
Could some one help me please ? Thank you
/*
CSV Format
userName,userEmail,userName
user1,user1@example.com,"User 1 Name"
user2,user2@example.com, "User 2 Name"
user3,user3@example.com, "User 3 Name"
CSV parsing code copied from: https://stackoverflow.com/questions/49675423/read-csv-file-and-put-result-in-a-map-using-groovy-without-using-any-external-l
*/
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
File file = new File("C:/Users/Ovyka/Desktop/mehdi/tryit.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])
def a = tmpMap.getAt("username", columns[0])
return a
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userService = ComponentAccessor.getComponent(UserService)
UserService.CreateUserRequest createUserRequest = UserService.CreateUserRequest.
withUserDetails(user, a.toString(), "password", "user@examplele.com", "Test User: user")
UserService.CreateUserValidationResult result = userService.validateCreateUser(createUserRequest)
if(result.isValid())
userService.createUser(result)
else
result.getErrorCollection()
csvMapList.add(tmpMap)
}
from jira import JIRA
import csv
import time
def create_user(row):
try:
jira.add_user(row[0], row[1], directoryId=dirnum, password=None, fullname=row[2], notify=False, active=True ignore_existing=True)
print("Added User: "+curuser)
except:
print("---- CAN'T ADD USER: "+curuser)
csvfile=sys.argv[1]
host=sys.argv[2]
uid=sys.argv[3]
passwd =sys.argv[4]
jira=JIRA(server=host, basic_auth=(uid, passwd))
f = open(csvfile, 'rb')
reader = csv.reader(f)
for user in users:
print('Creating ->', user[2])
create_user(user)
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.