Hello everyone,
We use GET request to download attachments from another Jira instance and attach it to our Jira so every time script runs twice and upload the same file to issue. I suppose I need to configure httpclient somehow but I can't find a solution. My code:
@BaseScript CustomEndpointDelegate delegate
attach ( httpMethod: "POST") {
MultivaluedMap queryParams, String body ->
//parsing json body from jira cloud
JSONObject json = new JSONObject(new JSONTokener(body))
JSONObject issue = json.getJSONObject("issue")
JSONObject fields = issue.getJSONObject("fields")
JSONArray attachments = fields.getJSONArray("attachment")
JSONObject attachment = attachments.getJSONObject(attachments.length() - 1)
String vendorRequest = fields.getString("customfield_11616")
String linkToFile = attachment.getString("content")
String fileName = StringUtils.substringAfterLast(linkToFile, "/")
//connecting to jira cloud to download file
CloseableHttpClient httpclient = HttpClients.createDefault()
HttpGet get = new HttpGet(linkToFile)
get.setHeader("X-Atlassian-Token", "no-check")
get.setHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxx==")
CloseableHttpResponse responseFromCloud = httpclient.execute(get)
HttpEntity entity = responseFromCloud.getEntity()
//attaching file to our jira
HttpPost post = new HttpPost("http://our-jira/rest/api/2/issue/" + vendorRequest + "/attachments")
post.setHeader("X-Atlassian-Token", "no-check")
post.setHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxx==")
InputStreamBody fileBody = new InputStreamBody(entity.getContent(), fileName)
HttpEntity entityToAttach = MultipartEntityBuilder.create().addPart("file", fileBody).build()
post.setEntity(entityToAttach)
CloseableHttpResponse responseFromServer = httpclient.execute(post)
responseFromCloud.close()
responseFromServer.close()
httpclient.close()
}
Any suggestions?
Regards,
Michael
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 NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.