Bulk editing user properties

Ye Fung Tchen
Contributor
October 27, 2020

Hey guys,

hope you can help me with this issue. We are using Jira 8.8.1 and I want to know if there is a way to bulk edit the user properties? I've got a lot of users and don't want to edit the properties manually for each of them. 

I need something which checks for the name in a excel file and if the name fits it should add the Key="Example" Value="Value" which is also stored in the excel table. 

Is this in any way possible to manage with a script or something else? 

3 answers

1 vote
Alibek Malikov February 16, 2023

import com.opencsv.CSVReader
import com.atlassian.jira.component.ComponentAccessor

def userPropertyManager = ComponentAccessor.getUserPropertyManager()

def userManager = ComponentAccessor.getUserManager()

def groupManager = ComponentAccessor.getGroupManager()

@GRAPES(
@grab(group='com.opencsv', module='opencsv', version='4.2')
)
def filePath = '/home/jira/YourFileName.csv'
def reader = new CSVReader(new FileReader(new File(filePath)))
def data= reader.collect { it }.with { rows ->
def header = rows.head()
def dataRows = rows.tail()

dataRows.collect { row ->
[header, row].transpose().collectEntries()
}
}

data.each{row->
def userObject = ComponentAccessor.userManager.getUserByName(row['user_login'].toString())
userPropertyManager.getPropertySet(userObject)?.setString("jira.meta.Position",row['position'].toString())
}

 

 

This is best script for run from script runner console.
You but rows to your exel table and add data to rows? then you save as .csv this file and put it to your server.

Vlad Fed October 21, 2024

Hi @Alibek Malikov 
Thanks for the solution
I used your script
Is it possible for it to ignore non-existent users in Jira?

1 vote
Vladimir
Contributor
October 27, 2020

I do not have the example but I am sure that it is possible. You have to write it by yourself.

And you can use either JIRA API for example here:https://docs.atlassian.com/software/jira/docs/api/7.0.6/com/atlassian/jira/user/preferences/UserPreferencesManager.html

 

or JIRA REST API, for example here:

https://community.atlassian.com/t5/Jira-Service-Desk-questions/Get-custom-user-properties-with-API/qaq-p/787587

 

Lastly if you have script runner you can write the groovy script.

It does not mean that you need excel. Excel is just one of the possibility how to write that script. You can use groovy, java, java script, php or a lot of others.

But sorry I do not have a time to write it. Maybe somebody else will have some examples.

Ye Fung Tchen
Contributor
October 27, 2020

Hey Vladimir,

thank you for the information. I will take a look into it!

0 votes
Alibek Malikov February 8, 2023

@Ye Fung Tchenhave you found a solution? If you have found a solution to the problem, can you tell me?

Suggest an answer

Log in or Sign up to answer