Skip to content

Instantly share code, notes, and snippets.

@jechlin-adaptavist
Created April 30, 2021 06:07
Show Gist options
  • Save jechlin-adaptavist/f08bd4c6c00ef5a29696fafa27c9ca96 to your computer and use it in GitHub Desktop.
Save jechlin-adaptavist/f08bd4c6c00ef5a29696fafa27c9ca96 to your computer and use it in GitHub Desktop.
write an issue as XML to a file... it's the same XML as shown by Export > XML
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.TrustedRequest
import com.atlassian.sal.api.net.TrustedRequestFactory
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import groovyx.net.http.URIBuilder
@PluginModule
TrustedRequestFactory trustedRequestFactory
final issueKey = 'SSPA-1'
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issueKey)
assert issue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def host = new URIBuilder(baseUrl).host
def xmlEndpointUrl = "/si/jira.issueviews:issue-xml/${issue.key}/${issue.key}.xml"
def request = trustedRequestFactory.createRequest(Request.MethodType.GET, "${baseUrl}$xmlEndpointUrl") as TrustedRequest
request.addTrustedTokenAuthentication(host, loggedInUser.username)
def result = request.execute()
new File("/tmp/${issue.key}.xml").withWriter { w ->
w.write(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment