My Jenkins multiline parameter is read in a variable SERVER_IP which is passed to Unix curl command as below:

The curl command triggers a webpage(Jenkins Build) and passes the parameters to the webpage.

curl  -k -X POST 'https://user1:[email protected]:9043/job/Scanner/buildWithParameters?SERVER_IP=\n10.9.20.13\n10.0.23.121&USER=root&REPORT_NAME=ihs_run' -H "Jenkins-Crumb:8c6f641ab7b9d1e7839c17a2be844490f2c88c5f9ae90c5ae5d52d7eae1"

I get the below error executing the curl command:

curl: (3) Illegal characters found in URL

Unfortunately; I do not have control over changing the SERVER_IP variable.

How can I get my curl command to pass the SERVER_IP values as is avoiding the error.

  • If you need the IP addresses to be newline-delimited, then possibly URL encode each newline as %0A?
    – Kusalananda
    Sep 18, 2020 at 16:39
  • https://www.urlencoder.org/ tells me the URL encode for \n is %5Cn . Am I correct ?
    – Ashar
    Sep 18, 2020 at 17:16
  • %5Cn would be the literal string \n ("backslash followed by n"). If this is what you want to send over, then use that. If you want \n to be a newline, then use %0A.
    – Kusalananda
    Sep 19, 2020 at 18:36

1 Answer 1


echo 'https://user1:[email protected]:9043/job/Scanner/buildWithParameters?SERVER_IP='${SERVER_IP}'&USER=root&REPORT_NAME=ihs_run' -H "Jenkins-Crumb:8c6f641ab7b9d1e7839c17a2be844490f2c88c5f9ae90c5ae5d52d7eae1" | sed ':a;N;$!ba;s/\n/\\n/g' | xargs curl -k -X POST

This link provides a good explanation on the sed command used in this example. I simply added \\n to stay inline with what I thought you wanted as a result. The sanatized version of the URL is then piped to xargs who will build and execute the command line from stdin.

As an example, the following would create a dir named one nesting dir two.

echo 'one/two' | xargs mkdir -p same as -> mkdir -p one/two

Hope that is clear. Glad it helped you out.

  • My code is like so curl -k -X POST 'https://user1:[email protected]:9043/job/Scanner/buildWithParameters?SERVER_IP=$SERVER_IP&USER=root So, how can i put ` <<EOF` in between the IPs <<EOF like how it is suggested in the answer ? @1nternetz
    – Ashar
    Sep 18, 2020 at 17:12
  • Kindly suggest @1nternetz as the answer does not help my case.
    – Ashar
    Sep 18, 2020 at 19:39
  • The --data-binary flag lets you feed curl data as-is. The @- or - tells curl to consume input from stdin. <<EOF is the end of stream indicator. This means it will consume everything until it hits EO, hence <<EOF would not appear in your code. Another trick could be GNU Bash ANSI C escaping. SERVER_IP=$'\n10.10.9.13\n10.0.23.121'&USER=root Notice the single quotes after the $. Hope this helps.
    – 1nternetz
    Sep 18, 2020 at 21:07
  • Sorry if I m not able to understand. I don't have to tell curl to consume from stdin as the data is stored in SERVER_IP variable. As suggested, I tried the following command which fails: curl --data-binary -k -X POST 'https://user1:[email protected]:9043/job/Scanner/buildWithParameters?SERVER_IP=$SERVER_IP&USER=root&REPORT_NAME=ihs_run' -H "Jenkins-Crumb:8c6f641ab7b9d1e7839c17a2be844490f2c88c5f9ae90c5ae5d52d7eae1" I get the following error: command not found: command not found: @1nternetz
    – Ashar
    Sep 18, 2020 at 21:47
  • Sorry, missread. I though you wanted to generate new lines in your curl command. Could you do something like this: echo 'https://user1:[email protected]:9043/job/Scanner/buildWithParameters?SERVER_IP='${SERVER_IP}'&USER=root&REPORT_NAME=ihs_run' -H "Jenkins-Crumb:8c6f641ab7b9d1e7839c17a2be844490f2c88c5f9ae90c5ae5d52d7eae1" | sed ':a;N;$!ba;s/\n/\\n/g' | xargs curl -k -X POST
    – 1nternetz
    Sep 19, 2020 at 3:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .