Comments on: How to export attachments from JIRA OnDemand and JIRA Cloud https://isbyr.com/how-to-export-attachments-from-jira-ondemand/ Infrequent Smarts by Reshetnikov Fri, 31 Mar 2023 03:25:19 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: Ilya Reshetnikov https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-9073 Fri, 31 Mar 2023 03:25:19 +0000 http://isbyr.com/?p=13#comment-9073 In reply to YMAC.

Appreciate sharing of the PowerShell script to the solution that allows to export attachments from Jira

]]>
By: YMAC https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-8964 Tue, 07 Mar 2023 21:47:17 +0000 http://isbyr.com/?p=13#comment-8964 When I used the updated script from Grayson it would work for a folder, but when it switched directories it started saying “The syntax of the command is incorrect”

current Dir. path is: C:\Jira
matched file path is: \Jira\Files\CMP\10000\CMP-1065\
matched file name is: 29764
Found row and ran command: ren 29764 “ScreenShot.jpg”
.
current Dir. path is: C:\Jira
matched file path is: \\Jira\Files\CMP\10000\CMP-1065\
matched file name is: 29765
Found row and ran command: ren 29765 “ScreenShot_2.jpg”
.
current Dir. path is: C:\Jira
matched file path is: \Jira\Files\CMP\10000\CMP-1068\
matched file name is: 29718
Found row and ran command: ren 29718 “ScreenShot_3.jpg”
The syntax of the command is incorrect.

If I stopped it the cmd prompt was in the correct directory and if I ran it again it would work for the next folder, I messed with it for awhile but could not get it to work. I gave up and converted it to a PowerShell script. I am sure there is a better way to do it, but the below worked for me.

$mainDirectory = “C:\Jira”
$filesToRename = “C:\Jira\Files”
$renameCmdList = “C:\Jira\NewnamesPS.txt”
# Get the file with all of the rename commands
$commands = Get-Content -Path $renameCmdList
# Cycle through each line of the file
foreach ($command in $commands) {
# Find the generic filename from the line by extracting the data after the .\
$filename = [regex]::Match($command, “\d+”).Value
# Display the filename
Write-Host “Filename:” $filename
# Search for the file in the filesToRename directory
$file = Get-Childitem -Path $filesToRename -Recurse | Where-Object { $_.Name -eq $filename }
# If the file is found, set the found directory as current and execute the line from the renameCmdList file
if ($file) {
Set-Location (Split-Path -Path $file.Fullname -Parent)
Write-Host “Current Path” $PWD.Path
Write-Host “Final:” $command
Invoke-Expression $command
# If the file is not found, report to console
} else {
Write-Host “Not Found”
}
}

The renameCmdList names file needs to be setup with the Powershell commands instead of the CMD ones like so:

Rename-Item -Path .\72633 -NewName “screenshot-1.png”

]]>
By: Prasad https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-6423 Fri, 08 Jul 2022 16:18:38 +0000 http://isbyr.com/?p=13#comment-6423 In reply to Christina.

hi, how did you do that?

]]>
By: Ilya Reshetnikov https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-5550 Wed, 13 Apr 2022 20:22:18 +0000 http://isbyr.com/?p=13#comment-5550 In reply to Grayson Bishop.

Thanks for that enhancement Grayson

]]>
By: Grayson Bishop https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-5549 Wed, 13 Apr 2022 16:38:55 +0000 http://isbyr.com/?p=13#comment-5549 For anyone looking at how this article who wants to keep all the attachments in the right folder for the ticket they’re associated with, check out the below batch script I wrote. You can use this instead of the commands in the “Copy files from all subfolders to a single folder” part of this article. Make sure you switch out the tokens accordingly.

@echo off
REM ^turn off echo so that only the output is written to the prompt, makes this a cleaner experience

REM run this by typing ‘{BATCH_FILE_withFullFilepath} > log.txt 2>&1’ into command line, which saves console output to the ‘log.txt’ file

REM this code is based on https://isbyr.com/how-to-export-attachments-from-jira-ondemand, but has been modified to keep attachments in their ticket’s sub-folder:
REM 1. Follow instructions to “Create backup for server” from a Jira Cloud instance, see https://support.atlassian.com/jira-cloud-administration/docs/export-issues/
REM 2. Extract the jira-export.zip file
REM 3. Follow steps in the article for “Extracting attachments’ file names”… use the same account that’ll run this script to avoid permission issues

REM this code will iterate through all the folders and change the file names from their unmarked file type and numeric filename to the correct name and file type.
REM this code assumes the following file structure which is standard for the Atlassian Jira Cloud backup for server zip file
REM ├──|attachments\
REM ├──{JIRAPROJECTKEY}\
REM ├──{10000_Grouping}
REM ├──{JIRA-TICKET-ID}
REM ├──{JIRA-TICKET-ID}
REM └──{JIRA-TICKET-ID}
REM └──{20000_Grouping}
REM ├──{JIRA-TICKET-ID}
REM ├──{JIRA-TICKET-ID}
REM └──{JIRA-TICKET-ID}
REM └──{JIRAPROJECTKEY}\

REM set the file paths you’ll need for everything
set mainDirectory={top-level-folder-with-extracted-zip-file}
set filesToRename={attachments-folder-inside-extracted-zip}
set renameCmdList={FilePath-of-text-file-with-ren-commands}

REM run this command to ensure the script starts in the right directory
cd /D %mainDirectory%

REM first, we’ll recurrsively loop through the folder and look for files
for /R %filesToRename% %%G in (*) do (
REM for every found file, search through the renameCmdList.txt file for the matching row…
REM the spaces in the search string ensure you get an exact match… e.g. to avoid 1001 matching with 10011…
REM then the output of the find (the matching row’s rename command) is pulled out and ran
REM the skip=2 skips the first line returned by the find which is just a header row with the folder path
REM the delims=” changes the delimiter from a space to a newline, since we want the whole line captured in one variable
REM if the file name is in the txt file, then this code will run
for /f “skip=2 delims=” %%Q in (‘find ” %%~nG ” %renameCmdList%’) do (
REM you need to cd into the right folder of the file b/c the commands in the txt file don’t have the full path
REM the ~p inside the %%G variable returns just the file’s path… the ~n returns just the file’s name
cd %%~pG

REM echo for troubleshooting
echo current Dir. path is: %CD%
echo matched file path is: %%~pG
echo matched file name is: %%~nG
echo Found row and ran command: %%Q

REM the find returns the full line the match was found on, which is itself a command, e.g. ‘ren 10532 “image001.jpg”‘
%%Q
)

REM add a blank line to keep the console/log legible
echo.

REM you can uncomment this pause for debugging
REM pause
)

REM move back to the mainDirectory where we started, just to keep it clean
cd %mainDirectory%

]]>
By: Grayson Bishop https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-5515 Thu, 07 Apr 2022 20:39:48 +0000 http://isbyr.com/?p=13#comment-5515 yeah this worked for me by using ” (straight quote character) instead of ” (curved quote character).

Read https://docs.oracle.com/javase/tutorial/essential/regex/groups.html to understand the capture groups and backreferences used in the regex equation in this article

]]>
By: Andrei Dvortsov https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-3037 Fri, 07 Aug 2020 11:40:18 +0000 http://isbyr.com/?p=13#comment-3037 I noticed that you use “ brackets, and my file had “. I changed that and it worked just fine. Maybe other people had same issue.

]]>
By: Ilya Reshetnikov https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-2550 Thu, 24 Oct 2019 20:06:44 +0000 http://isbyr.com/?p=13#comment-2550 In reply to Gursimran Kaur.

Is there any content after the line numbers? as I can’t see anything in the comment?

]]>
By: Gursimran Kaur https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-2547 Wed, 23 Oct 2019 11:36:19 +0000 http://isbyr.com/?p=13#comment-2547 In reply to Ilya Reshetnikov.

Here are some lines:

Line 1947683:
Line 1947684:
Line 1947685:

]]>
By: Gursimran Kaur https://isbyr.com/how-to-export-attachments-from-jira-ondemand/#comment-2541 Mon, 21 Oct 2019 12:58:22 +0000 http://isbyr.com/?p=13#comment-2541 In reply to Ilya Reshetnikov.

Hi,
I am facing same issue for Find and Replace.

Line is :

Line 1947698:

Can you please help?

]]>