Hello I’m hoping someone can shed some light on this problem. I’m trying to do a simple call from ScriptRunner on Bitbucket, running as a custom event handler during a pull request. For now, I’m just trying to get the contents of a Jira issue to process but I keep getting authorization errors.
Our Bitbucket is configured to have an application link to Jira using local OAuth authentication in both directions.
I’ve shown the script portion below. I’ve tried using various request factory with different results. I’ve reviewed all the community responses I can find and none give me any more ideas besides passing credentials, which I believe it not supposed to be done anymore?
When I use createImpersonatingAuthenticatedRequestFactory or createAuthenticatedRequestFactory it will generate a "CredentialsRequiredException" with message "You do not have an authorized access token for the remote resource". The same goes if I try just a normal createRequestFactory. If I use the createNonImpersonatingAuthenticatedRequestFactory it does not generate an exception but returns a response code of 401 in the log.
String jiraTicket = "BTP-1" // test ticket on engdev Jira board BTP
def jiraLink = getJiraAppLink()
// note: createNonImpersonatingAuthenticatedRequestFactory does not cause
// an exception but returns code 401
// createImpersonatingAuthenticatedRequestFactory causes an
// exception (no authorized access token)
// createAuthenticatedRequestFactory causes an exception (no
// authorized access token)
def requestFactory = jiraLink.createNonImpersonatingAuthenticatedRequestFactory()
requestFactory
.createRequest(Request.MethodType.GET, "rest/api/latest/issue/" +
jiraTicket)
.addHeader("Content-Type", "application/json")
.execute([
handle: { Response response ->
if (response.isSuccessful()) {
log.info("received successful response")
String responseString = response.getResponseBodyAsString()
log.info(responseString)
} else {
log.info("Failed to get response from Jira: code " +
response.getStatusCode())
log.info("Text: " + response.getStatusText())
}
}] as ApplicationLinkResponseHandler<Void>
)