Hi all.
I'm making a scripted post-function that automatizes the Confluence space creation in a certain transition of my workflow. Since I'm doing this from Jira, I needed to write a script, and it is working fine, but when I call the built-in script "Copy Tree", from Scriptrunner, I get the following error:
Cannot invoke method getSpace() on null object, stack-trace=java.lang.NullPointerException: Cannot invoke method getSpace() on null object at com.onresolve.scriptrunner.canned.confluence.admin.CopyTree.doValidate(CopyTree.groovy:237)
The block of code where I call this:
import com.atlassian.sal.api.component.ComponentLocator
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import groovyx.net.http.Method
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import org.apache.http.protocol.HttpContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.Field
import java.lang.Long
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def fieldSpaceKey = customFieldManager.getCustomFieldObject("customfield_15629")
def getApplicationConnection(String url) {
def http = new HTTPBuilder(url)
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + '*****:*****'.bytes.encodeBase64().toString())
httpRequest.addHeader('X-Atlassian-Token', 'no-check')
}
})
return http
}
def copyAgileSpaceTemplate(sourcePage, targetPage, projectKey) {
def copyPageTreeParams = [
FIELD_SRC_PAGE_ID: "[\"" + sourcePage + "\"]",
FIELD_TARGET_PAGE_ID: "[\"" + targetPage + "\"]",
FIELD_TITLE_TRANSFORM: "import com.atlassian.confluence.pages.AbstractPagetitleTransform = {AbstractPage p -> p.title = '${projectKey} ' + p.title}"
]
def confluence = getApplicationConnection("confluence_base_url")
confluence.request(Method.POST, ContentType.JSON) { req ->
uri.path = "rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.confluence.admin.CopyTree"
send ContentType.URLENC, [scriptParams: new JsonBuilder(copyPageTreeParams)]
response.success = { resp, json ->
log.warn("CopyTree response status: ${resp.statusLine}")
assert resp.statusLine.statusCode == 200
}
response.failure = {resp, json ->
log.warn(json)
}
}
}
copyAgileSpaceTemplate(83460136, 93683725, "ISJC")
It looks like that some part of the source code of the built-in script can't understand the parameters given.
I'm using Jira Server 7.2.3 and Scriptrunner 4.3.13.
Thanks in advance!!