Hello everyone, I’m working on a JIRA project and need to rename attachment files in bulk. Specifically, I need to convert file names from Cyrillic to Latin characters. Here’s what I’m trying to achieve: Transliterate File Names: Convert file names from Cyrillic to Latin characters using a predefined mapping. Rename Files: Update the file names in JIRA to reflect the transliterated names.
I don't think there is a good way to rename the attachment while it is still attached to the ticket. There are too many things that would need to be changed like the file on the server, the attachment data in the database and then other information that links it to the ticket.
The only way I cold see this being done is to:
Several of my go-to tools were not able to do this but I do know that a product called Power Scripts can do it. Here is an example script that shows how it can be done. This is just a starting point, I would add logging to it however it works:
struct renameData {
string oldFileName;
string newFileName;
}
renameData [] data = readFromCSVFile("renameData.csv", true);
string [] dataMapped;
for(renameData d in data) {
dataMapped[d.oldFileName] = d.newFileName;
}
string [] issueKeys = selectIssues("project = TEST");
for(string key in issueKeys) {
integer [] attach = getAttachmentIds(key);
for(integer a in attach) {
string oldFileName = attachmentFilename(key, a);
boolean downloaded = downloadAttachmentById(key, a, "C:/downloads/" + oldFileName);
if(downloaded) {
deleteAttachment(key, a);
string newFileName = dataMapped[oldFileName];
renameFile("C:/downloads/" + oldFileName, "C:/downloads/" + newFileName);
uploadAttachment(key, "C:/downloads/" + newFileName)
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.