I have two JIRA instances located in two different data-centers.
I am trying to develop a functionality via workflow post function that would copy attachments from issue in Instance A to an issue in Instance B.
I have scriptrunner in both of my JIRA instances.
For now I am just trying to get one attachment via API and upload it to an issue in the same instance via API.
The code below creates the attachment (I am running it from ScriptRunner script console) - however I am only able to upload text attachments.
def connection = new URL("https://xxxx/secure/attachment/10108/test.txt").openConnection() as HttpURLConnection
connection.setRequestMethod( "GET" )
connection.setRequestProperty( "Authorization", "Basic xxxxxxxxxxx" )
connection.doOutput = true
def image = connection.inputStream.text
def body = "---\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Type: text/plain\r\n\r\n $image \r\n---"
def upConnection = new URL("https://xxxxxxxxxxxxx/rest/api/latest/issue/xxxxxxxxxx/attachments").openConnection() as HttpURLConnection
upConnection.setRequestMethod( "POST" )
upConnection.setRequestProperty( "Authorization", "Basic xxxxxxxxx" )
upConnection.setRequestProperty( "X-Atlassian-Token", "nocheck" )
upConnection.setRequestProperty( "Content-Type", "multipart/form-data; boundary=-")
upConnection.doOutput = true
def upCode = upConnection.getResponseCode();
def upResult = upConnection.inputStream
I'm not really an expert on the inputStream and how to pass the data while preserving the file type.
Scriptrunner allows you to place .groovy scripts under <jira-home>/scripts. With this, you can save a tmp file on the same directory for the attachment. For the saving the file, you can save the inputStream into a tmp file; Java – Write an InputStream to a File.
I believe Script Console and workflow post-function allows you to choose a script from the filesystem rather than providing inline scripts.
Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events