Jira CLI question -- how to download attachments for more than one issue?

Bryan Karsh
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.
July 3, 2014

Hi,

I've been using the JIRA CLI tool (great kit by the way). I followed examples to download an attachment list of all issues from a search query like so:

./jira.sh --action runFromIssueList --filter FOO-test --common "--action getAttachmentList --outputFormat 2 --issue @issue@ --file list.csv --append"

I also followed an example to download attachment(s) for a single issue. For example:

./jira.sh --action runFromAttachmentList --issue "FOO-1036" --common "-a getAttachment --file \"target/output/jiraclirunner/@attachment@\" --name @attachmentId@ --issue FOO-1036"

.. this is great. But how do I download all attachments from an attachment list (that I get from my first search?)

1 answer

1 accepted

2 votes
Answer accepted
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
July 4, 2014

You are doing good by breaking it down into working pieces. Now, you just need to combine them all and be careful with the quoting/escaping.

--action runFromIssueList --filter FOO-test --common "--action runFromAttachmentList --issue @issue@ --common \"--action getAttachment --issue @issue@ --file \"\"target/@attachment@\"\" \" "

Bryan Karsh
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.
July 4, 2014
Excellent.. so you can nest common activities. Nice. Thanks for the quick response!
Bryan Karsh
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.
July 7, 2014

Hi Bob,

I am running into something interesting. If I run this:

./jira.sh --continue --verbose --action runFromIssueList --filter FOO-test --common "--action runFromAttachmentList --issue @issue@ --common \"--action getAttachment --issue @issue@ --file \"\"target/@attachment@\"\" \" "

The script runs, but I get errors like the following. Some of the attachments have titles matching the issue they are assigned to, so I was able to see where there was a disconnect:

Client error: Attachment 'Blah-blah-blah-FOO-2866.xlsx' not found for issue FOO-2864
org.swift.common.cli.CliClient$ClientException: Attachment 'Blah-blah-blah-FOO-2866.xlsx' not found for issue FOO-2864

I was able to verify that the attachment does exist on FOO-2866, and not FOO-2864. Tips?

Bob Swift OSS (Bob Swift Atlassian Apps)
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.
July 7, 2014

Hard to say, can you please open an issue with more detail of the log showing and version information? So the other attachments worked, just not this one?

Bryan Karsh
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.
July 7, 2014

Pretty much all fail -- unless there is an attachment that just happens to be in more than one issue. I created JCLI-532 with some exampels. I'll attach output of full run as well.

Bryan Karsh
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.
July 12, 2014

Had a related question:

Is there a way to use Jira CLI to download attachments specified in the file you get from getAttachmentList? For example, with use runFromAttachmentList? The --file option for that seems to imply the output as opposed to the input.

I was able to do it this way, but I'd prefer not to login/logout so many times:

for i in `cut -d \" -f 2 attachments.csv | sort -u`; do ./jira.sh --action runFromAttachmentList --issue $i --common "-a getAttachment --file \"target/@attachment@\" --name \"@attachment@\" --issue $i"; done

Lastly, regarding testing problems with I encountered with the example you gave me. It looks like the @attachment@ variables don't clear when script moves to next issue. Output shows success for the first issue, then failures for the rest. Is there a way to flush/clear a variable between iterations?

Bryan Karsh
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.
July 12, 2014

sorry -- one more question. How do we add timestamps and the user who added the attachment when importing? Do I need to resort to atlassian csv import for that?

Bob Swift OSS (Bob Swift Atlassian Apps)
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.
July 12, 2014

I believe there is a regression error in 3.9, try using release 3.8 until it is fixed in 4.0.

Regarding the other information, I would recommend adding a comment immediately after adding the issue with whatever details you want. JIRA doesn't provide any other way to associate a comment for a specific attachment.

Bryan Karsh
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.
July 12, 2014

Thanks Bob -- version 3.8 seems to work as expected. You sir rock!

What I meant earlier wasn't regarding comments specificially. I meant that if an attachment in the original issue had a timestamp and user associated with it, is it possible to recreate that data via your tool?

Suggest an answer

Log in or Sign up to answer