Replace Confluence attachment via command line

I have a swag of attachments (pngs) that I need to replace throughout a Confluence instance. These files are matched on filename. I can match a file invidiually, running getAttachmentList --regex "<filename>" gives me a match, but then what?

I wasn't able to get --common '-a addAttachment --file "filepath"' to then replace those files.

Anyone tried replacing image attachments en masse and had much luck?

2 answers

1 accepted

Bingo!

Here's the command for anyone that wishes to do the same thing:

confluence -a runFromAttachmentList --space theSpace --regex "theimage.png" --common "-a addAttachment --space @space@ --title \"@title@\" --comment \"inserted via command line\" --file \"C:\filepath\image.png\" "

From here on in, batching is just a matter of mapping the parameters for the replacement files. You could also increase the scope of files with different parameters for the runFromAttachmentList, such as broadening the regex scope.

Thanks very much for your help Bob! (^_^)

You would need to use runFromAttachmentList which is similar to getAttachmentList, but it will run an action for each attachment found. Variable replacements would provide the necessary parameters for the addAttachment action.

Thanks for that Bob.

Just an additional query, when I run the command:

confluence -a runFromAttachmentList --space thespace --regex "image.png" --common "-a addAttachment --space @space@ --title "@title@" --comment 'inserted via command line' --file "C:\filepath\image.png"" --simulate

I get:
Simulate: -a addAttachment --space thespace --title Image Title --comment 'inserted via command line' --file C:\filepath\image.png

Run completed successfully. 1 actions were successful

But when I run the same command without the simulate, I get:

Error: Unexpected argument: Title
Error: Unexpected argument: via
Error: Unexpected argument: command
Error: Unexpected argument: line'

I've tried with both quotes and apostraphes, but still no dice. Is it a glaring mistake somewhere I'm not seeing?

You have quotes within quotes that need to be handled - see the quoting section of Tips

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,695 views 26 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you