Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to update a jira issue from bitbucket on a pull request using scriptrunner?


I'm trying to write an event handler in Scriptrunner for BitBucket such that on the PullRequestMergedEvent it should find all related issues and add the fixVersion to it based on the release branch the request was merged to. 

I've been able to write a cURL request which does what I want, just to test that I was creating the proper payload for the request.  Here is the cURL request I made which corresponds to what I'd like the script to do:

curl -u user:pass -X PUT --data '{"update":{"fixVersions":[{"add": {"name":"Release 10-7"}}]}}' -H "Content-Type: application/json" https://server/rest/api/2/issue/JA-30

Where I've subbed out the username/password and server url components of course.  

Now I'm trying to do the same thing in groovy, I'm using the sample in the Scriptrunner for Bitbucket for updating all related issues with a comment about the pull request ( with modifications to run in the script runner console.

import com.atlassian.applinks.api.ApplicationLinkResponseHandler
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonSlurper

// Stuff that I added for handling the stuff I want to do
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketBaseScript
import com.atlassian.bitbucket.pull.PullRequestSearchRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.applinks.api.ApplicationLinkRequest
@BaseScript BitbucketBaseScript baseScript

// This part here is only to retrieve a pull request. 
// Will be replaced by the pull request merged event in practice
def prService = ComponentLocator.getComponent(PullRequestService)
def prsrBuilder = new PullRequestSearchRequest.Builder();
def pullRequestSearch =;
def pageRequest = new PageRequestImpl(0, 25);
def page =, pageRequest);
def prIter = page.getValues().iterator();
def pr =;

// Start of real work
def keys = jiraIssueService.getIssuesForPullRequest(50,*.key;
def jiraLink = getJiraAppLink();

// making the request
def releaseVersion = "Release 10-7";
def builder = new StringBuilder();
builder.append("{ \"update\": ");
builder.append("{ \"fixVersions\": ");
builder.append("[{ \"add\": ");
builder.append("\"name\": \"" + releaseVersion + "\" }}]");
def input = builder.toString();

def handler = new ApplicationLinkResponseHandler<Map>() {
    Map credentialsRequired(Response response) throws ResponseException {
        return null

    Map handle(Response response) throws ResponseException {
        assert response.statusCode == 200
        new JsonSlurper().parseText(response.getResponseBodyAsString()) as Map 
def applicationLinkRequestFactory = jiraLink.createAuthenticatedRequestFactory() 

// Just so I can see what's in the response
def response; // Making the requests for each issue key found. keys.each { String key -> ApplicationLinkRequest aRequest = applicationLinkRequestFactory.createRequest(Request.MethodType.POST, "/rest/api/2/issue/$key"); aRequest.addHeader("Content-Type", "application/json"); aRequest.setEntity(input); response = aRequest.execute(handler); } // Just some sample return value in the script runner console return "Making the request as: " + input + " " + response


I can run a GET request, commenting out the entity body part and changing the request type, but when I try to do a post, I always get an HTTP 405 response instead of a 200.  It seems like it doesn't do the analogous "-X PUT" part of the curl request.  Can someone shed any light on what I need to change with my request to make this work properly?

BTW we are using JIRA Server Software 7.2.7 and Bitbucket Server 4.13.  We have Scriptrunner installed on both.  

Thanks in advance!

1 answer

Looks like in transposing my cURL request to the sript form, I missed a brace in the composition of the update body so that was why it was failing!  D'oh!

Katy Kelly
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 15, 2017

Hi Jeff,

I'm sorry to hear you had some difficulties, but glad to see you were able to locate the problem. Did adding the missing brace resolve this for you? If not let us know and we'd be happy to help troubleshoot further. 



Adaptavist Product Support 

yes, gotta what those brackets!!  

Katy Kelly
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 15, 2017

They can be tricky! Glad to hear that fixed the issue. Have a great day!


Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events