Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I copy attachments from a JIRA Issue to a Confluence page on transition?

Christopher Siebert
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 8, 2018

I am using JIRA for approval process and when the attachments are transitioned to "Done" I would like to use ScriptRunner (or maybe something else?) to copy the attachments from the JIRA issue into a specific Confluence Page. 

4 answers

1 vote
Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2018

Why would that be helpful? I would use references rather than copying the actual data

1 vote
Simon Merrick
Contributor
November 8, 2018 edited

Cloud or Server? Might be possible with Script Runner in cloud and probably also server with the REST API only - but I haven't tried it.

How's your scripting? I'm not going to go to deep into the scripting but I will post some snippets which might help you.

There's a Jira REST API endpoint to get attachments
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/attachment-getAttachment

And a Confluence REST API endpoint to create attachments
https://docs.atlassian.com/ConfluenceServer/rest/6.12.1/#content/{id}/child/attachment-createAttachments

So from Jira you could have a Workflow Postfunction or ScriptRunner Listener to run a groovy script to get attachments from the Jira issue and Post to a confluence page.

You can download the attachment(s), keeping them in memory, and upload them elsewhere, still from memory. Here's a code snippet of copying attachments from one jira ticket to another in this fashion. (The language is Groovy).

if (issue.fields.attachment) {
    issue.fields.attachment.collect { attachment ->
        def url = attachment.content as String
        url = url.substring(url.indexOf("/secure"))
        def is = Unirest.get("${url}").asBinary().body
        def resp = Unirest.post("/rest/api/2/issue/${clonedIssue.id}/attachments")
                .header("X-Atlassian-Token", "no-check")
                .field("file", is, ContentType.create(attachment.mimeType), attachment.filename)
                .asObject(List)
        assert resp.status >= 200 && resp.status < 300
    }
}


The only thing I am not sure about is that I think that scriptrunner limits what API's you can call - I am pretty sure you can't make HTTP requests to arbitrary services (google, facebook etc). I don't know how constrained this limitation is.

The other challenge to solve is unless you are posting attachments to the same confluence page every time then you would need a way to dynamically specify which confluence page it should go to. You could store the ID or URL of the confluence page in a custom field on the issue and then read the value and interpolate it into the url.

0 votes
Vamshee Rangu July 31, 2019

I am looking solution for the similar problem. I have a requirement similar to this. All the work is done JIRA but the attached documentation should be Confluence. People will be working off JIRA but all the attachments should go into Confluence with JIRA issue number, date and time.

I was hoping automation for JIRA would help (still waiting on approvals).

Thank you

Vamshee

0 votes
Simon Merrick
Contributor
November 8, 2018

Actually I don't think it will work talking to another system using script runner as I am pretty sure script runner talks to your Jira using JWT and you wont be able to auth with the confluence - that might be a question to raise with Adaptavist support.

You could use Webhooks to talk to your own Webservice which listens for events / webhooks from Jira and then once again uses the REST API to get the attachments from Jira and push it to confluence.

The web service wouldn't have to be very big - maybe 30 lines of python running as a flask application. But it comes with the additional overhead of needing to be hosted.

The short answer is I think it's definitely possible depending on how far you are willing to go and what you consider reasonable effort. Maybe someone else in the community has a simpler solution?

Simon Merrick
Contributor
November 8, 2018

...did my original comment get deleted?

Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2018

And ... it's back

Like Simon Merrick likes this
Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2018

I think you could use the App Link set up between your Jira and your Confluence to modify Confluence pages

Simon Merrick
Contributor
November 8, 2018

Weird, anyway seeing your response I tend to agree - this 'solution' would be duplicating data.

My answer addresses the question of 'could I?' but not 'should I?'

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events