Itai Ganot Itai Ganot - 1 year ago 63
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:

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 Source

How about something like this:-

def CURL_COMMAND = "${MP_BASE_URL}${REQUEST_URL}&sig=${SIGNATURE}".replaceAll(' ','%20')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download