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 get specific value from the script runner result

Hi All, 

I got the result after running the groovy script in script runner. But I need to catch id in a  variable. 
How is it possible to catch the value of Id in a variable? 


import static*
import groovy.json.JsonOutput
import net.sf.json.groovy.JsonSlurper
import groovy.json.JsonSlurper

def authString = "user:passwd".bytes.encodeBase64().toString()

def bodyJson = JsonOutput.toJson([name: "Testing Automate deployment", planKey:["key":"TP-MS"], description:"Testing REST API"])

def slurper = new groovy.json.JsonSlurper()

def http = new HTTPBuilder( '' )
http.request(PUT) {
headers."Authorization" = "Basic ${authString}"
body = bodyJson
requestContentType = ContentType.JSON

//response.success = { resp ->
//log.warn "Creating new delpyment project request Success! ${resp.status}"

response.failure = { resp, reader ->
log.warn "Creating new delpyment project request Success! ${resp.status}"


response.failure = { resp ->
log.warn "Creating new delpyment project request failed with status ${resp.status}"
log.warn resp.statusLine





[id:33587298, oid:8rpzfqhc4p5u, key:[key:33587298], name:Testing Automate deployment, planKey:[key:TP-MS], description:Testing REST API, environments:[], operations:[canView:true, canEdit:true, canDelete:true, allowedToExecute:false, canExecute:false, allowedToCreateVersion:true, allowedToSetVersionStatus:false], repositorySpecsManaged:false]

1 answer

1 accepted

0 votes
Answer accepted

There are a couple of ways you can return a value from a closure (everything in the curly brace after http.request(PUT) is a closure)

You can assign the whole statement to a variable 

def myRequestOutput = http.request(PUT){...}

Then you can extract the id from that object with

def id =

That works because the httpbuilder will automatically slurp the json into an object

The second way is to define the variable before the closure and fill it inside in a success call:

def myId
response.success = {httpResponse, slurpedJson ->
myId =

Hi Peter, 

 It 's working .Thank you :) .

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events