Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Get the Name of the Workflow

Created 1 year ago, Updated 23 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.12 - 8.22)
compatibility bullet
ScriptRunner For Jira (6.56.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
getWorkflowNames { MultivaluedMap queryParams ->
    def applicationProperties = ComponentAccessor.applicationProperties

    final def hostUrl = applicationProperties.getString('jira.baseurl')

    final def projectKey = queryParams.getFirst('projectKey')

    final def username = '<USERNAME>'
    final def password = '<PASSWORD>'

    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/projectconfig/1/workflowscheme/${projectKey}") as HttpResponseDecorator

    if (resp.status != 200) {
        log.warn 'Commander did not respond with 200'
    }

    def workflowName = resp.data['mappings']['name'] as List

    Response.ok(new JsonBuilder(workflowName.first()).toPrettyString()).build()
}
Having an issue with this script?
Report it here