I copy the following copy from adaptavist library:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.Issue
// the name of the field to copy
final String fieldNameToCopy = "Priority";
// leave blank to copy from the last linked issue (regardless the link type)
final String issueLinkTypeName = "Blocks"
def fieldManager = ComponentAccessor.fieldManager
def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
if (!fieldToCopy) {
log.info "Could not find field with name $fieldNameToCopy"
return
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id)
if (!linkedIssues) {
log.info "There are no linked issues"
return
}
if (issueLinkTypeName && !(issueLinkTypeName in linkedIssues*.issueLinkType*.name)) {
log.info "Could not find any issue, linked with the $issueLinkTypeName issue type"
return
}
def linkedIssue = issueLinkTypeName ?
linkedIssues.findAll { it.issueLinkType.name == issueLinkTypeName }.last().destinationObject :
linkedIssues.last().destinationObject
def fieldToCopyId = fieldToCopy.id
switch (fieldToCopyId) {
case fieldManager.&isCustomFieldId:
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
def linkedIssueCustomFieldValue = linkedIssue.getCustomFieldValue(customField)
issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue)
break
case IssueFieldConstants.COMPONENTS:
def commonComponents = linkedIssue.components.findAll { it.name in issue.components*.name }
issue.setComponent(commonComponents)
break
case IssueFieldConstants.FIX_FOR_VERSIONS:
def commonFixedVersions = linkedIssue.fixVersions.findAll { it.name in issue.fixVersions*.name }
issue.setFixVersions(commonFixedVersions)
break
case IssueFieldConstants.AFFECTED_VERSIONS:
def commonVersions = linkedIssue.affectedVersions.findAll { it.name in issue.affectedVersions*.name }
issue.setFixVersions(commonVersions)
break
default:
issue[fieldToCopyId] = linkedIssue[fieldToCopyId]
}
But I get unknown methods error. Don't know why...
Someone could help me. thanks
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
Muchas gracias Alejandro;
Es justo lo que necesitaba:
It was wonderful, cause is Exactly that I need.
Thank's
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ContentTypeBecause if not put, it will be an error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.