groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Matz <guym...@gmail.com>
Subject RESTClient error when POSTing JSON with embedded GString
Date Wed, 27 Apr 2016 16:36:30 GMT
Hi!  The code below chokes when I try to use the GString "${build.number}"
within the fields var.  The error I get is:
Apr 27, 2016 12:32:25 PM net.sf.json.JSONObject _fromBean
INFO: Property 'value' of class org.codehaus.groovy.runtime.GStringImpl has
no read method. SKIPPED

Anyone know what I'm doing wrong there?  Works fine when i use a regular
string

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON

def build=['number':456]
def changes=['data':'123 -> 124', 'render':'234 -> 235','web':'678 -> 679']
def jiraUser='jira'
def jiraPassword='password'
def changelog='ch-ch-ch-ch-changes'

def jiraProject = 'Change Management System'
def jiraProjectCode = 'CMS'
def *fields* = ['project': [key:'CMS'],
   'issuetype': [name:'Continuous Delivery'],
   // 'summary': "Changes in QA Deploy ",
   'summary': "Changes in QA Deploy #*${build.number}*",
   'description': changelog,
   'customfield_20904': build.number.toString(),
   'customfield_20905': changes['data'],
   'customfield_20906': changes['render'],
   'customfield_20907': changes['web']
]
def reqParams = [
  fields : fields
]

def jiraServer = 'https://stage.atlassian.net'
def createTicketPath = '/rest/api/latest/issue'

def rest = new RESTClient(jiraServer)
rest.headers['Authorization'] = 'Basic
'+"${jiraUser}:${jiraPassword}".bytes.encodeBase64()

try {
  println "Attempting REST call with . . ." + reqParams
  def resp = rest.post( path : createTicketPath, body: reqParams,
contentType: JSON)
  println resp.status
  println resp.data
}
catch(Exception e) {
  println "ERROR!!! " + e
}

Mime
View raw message