Itai Ganot Itai Ganot - 1 month ago 8
Groovy Question

Groovy: How to include special characters in a variable and glue it with other variables?

I'm trying to build a curl command:

CURL_COMMAND = ${MP_BASE_URL}${REQUEST_URL}&sig=${SIGNATURE}.replaceAll(' ','%20')


When I run the code I get the following error:

unexpected token: & at line: 34, column: 52


The CURL_COMMAND variable should look like that:

http://mixpanel.com/api/2.0/annotations/create?api_key=XXXXXXXXXb45f&date=2016-10-18%14:58:29&description=Android%v4.2.1&expire=1588896000&sig=da9ad3baf429001b29cbf9adjshkhk3


But I'm having trouble getting the "&" to be printed as part of the URL.

here are some of my tries:

CURL_COMMAND = "${MP_BASE_URL}${REQUEST_URL}'&sig='${SIGNATURE}.replaceAll(' ','%20')"
CURL_COMMAND = "${MP_BASE_URL}${REQUEST_URL}+'&sig='+${SIGNATURE}.replaceAll(' ','%20')"


Any ideas how can I accomplish my aim?

Answer

How about something like this:-

def CURL_COMMAND = "${MP_BASE_URL}${REQUEST_URL}&sig=${SIGNATURE}".replaceAll(' ','%20')