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

I can update the attachment whit groovy CLOUD

Eduard Diez
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.
February 11, 2019

I have this code to update the new SubTask in  transition, but I have problems to put the news attachments:

Captura.PNGCaptura2.PNG

 

2 answers

2 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 16, 2019

I found this code, and tested it. It works fine, you could addapt it for your purpose:

import org.apache.http.entity.ContentType

def getIssue = 'SD-3'
def result = get('/rest/api/2/issue/' + getIssue)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
logger.info('sucess')
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}

result.body.fields.attachment.collect {
attachment ->
def url = attachment.content as String
url = url.substring(url.indexOf("/secure"))
def fileBody = Unirest.get(url).asBinary().body
def postIssue = 'SD-4'
def postResult = Unirest.post("/rest/api/2/issue/" + postIssue + "/attachments")
.header("X-Atlassian-Token", "no-check")
.field("file", fileBody, ContentType.create(attachment['mimeType'] as String), attachment['filename'] as String)
.asObject(List)
assert postResult.status >=200 && postResult.status < 300
}

Regards 

Eduard Diez
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.
February 18, 2019

Muchas gracias Alejandro;

Es justo lo que necesitaba:

 

It was wonderful, cause is Exactly that I need.

Thank's

Eduard Diez
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.
February 18, 2019

For all the people that need a similar Script or same Script, In CLOUD is very important (in this case) to put the import class.

import org.apache.http.entity.ContentType

Because if not put, it will be an error

2 votes
Answer accepted
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 16, 2019
TAGS
AUG Leaders

Atlassian Community Events