We are currently trying to use ScriptRunner to execute a workflow transition on a remote JIRA instance via a post function and are running into some interesting issues. Basically, we have a custom workflows on two JIRA instances (say A and
. When we execute a specific workflow transition on an issue in A, we want to also execute a workflow transition on a remotely linked issue in B.
I have attached the script we are using. It starts off by declaring parameters that are going to be used in the remainder of the script. It then grabs all remote issue links for the current issue, and for each one of them, calls the executeTransition function. That function will grab all transitions for the remote issue using the JIRA REST API, find the appropriate transition, and then make a POST call to the JIRA REST API to execute the workflow transition.
Here is the API call https://docs.atlassian.com/jira/REST/latest/#api/2/issue-doTransition. We also use cURL in order to accomplish this (I haven't found a better way of making POST requests using the native groovy language).
Here's the issue we are running into: the script works everywhere EXCEPT in JIRA instance A. I have a local copy of JIRA and the script works just fine there. We even made a dummy field that would spit out the cURL commands generated by the script (specifically the one in line 63), then tried executing those commands in command line on a local machine AND in bash on the server that hosts JIRA instance A. The cURL command generated by the script works in both cases, it just doesn't work when we call curl.execute() (line 64) in the script.
We're not sure why it's working only outside of that specific instance of JIRA and were wondering if you have any clue as to what could be causing this.
Thank you for any help you can provide!
package clearleap
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLink
import groovy.json.JsonSlurper
// === BEGIN PARAMETERS ===
def curlCmd = "curl"
def username = "USERNAME"
def password = "PASSWORD"
def transitionName = "TRANSITION_NAME"
def protocol = "https://"
// === END PARAMETERS ===
RemoteIssueLinkService linkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class)
String requestAuth = ""
String requestData = ""
String request = ""
String curl = ""
InputStream response;
Map responseObj;
def executeTransition = { RemoteIssueLink link ->
String url = link.getUrl()
if(!url || url.length() == 0 || !url.contains(protocol))
return
String remoteBaseUrl = url.substring(0, url.indexOf("/", url.indexOf(protocol) + protocol.length()))
String remoteIssueId = url.substring(url.lastIndexOf("/") + 1)
request = "$remoteBaseUrl/rest/api/2/issue/$remoteIssueId/transitions"
curl = "$curlCmd -u $username:$password $request"
response = curl.execute().inputStream
responseObj = new JsonSlurper().parse(response) as Map
ArrayList<Map> transitions = responseObj.transitions as ArrayList<Map>
String transitionId = null
transitions.each { Map transition ->
if(transition.name == transitionName) {
transitionId = transition.id
}
}
if(transitionId == null || transitionId.length() == 0)
return
requestAuth = "Basic " + "$username:$password".bytes.encodeBase64()
requestData = """
{
\\"transition\\": {
\\"id\\": \\"$transitionId\\"
}
}
"""
request = "$remoteBaseUrl/rest/api/2/issue/$remoteIssueId/transitions"
curl = "$curlCmd -H \"Content-Type: application/json\" -H \"Authorization: $requestAuth\" -X POST -d \"$requestData\" -u $username:$password $request"
curl.execute()
}
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def getLinksResult = linkService.getRemoteIssueLinksForIssue(loggedInUser, issue)
getLinksResult.getRemoteIssueLinks().forEach { RemoteIssueLink link ->
executeTransition(link)
}