Example scripts
To homepage
Jira

Copy Versions from one Project to Another
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.20)

ScriptRunner For Jira (6.38.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
getVersions { MultivaluedMap queryParams ->
def applicationProperties = ComponentAccessor.applicationProperties
def hostUrl = applicationProperties.getString('jira.baseurl')
//Specify the Username
def username = '<USERNAME>'
//Specify the Password
def password = '<PASSWORD>'
//Specify the Project Key
def projectKey = '<PROJECT_KEY>'
final def headers = ['Authorization': "Basic ${"${username}:${password}".bytes.encodeBase64()}", 'Accept': 'application/json'] as Map
def http = new RESTClient(hostUrl)
http.setHeaders(headers)
def resp = http.get(path: "/rest/api/2/project/${projectKey}/versions") as HttpResponseDecorator
if (resp.status != 200) {
log.warn 'Commander did not respond with 200'
}
def row = resp.data['name']
Response.ok(new JsonBuilder(row).toPrettyString()).build()
}
Having an issue with this script?
Report it here