Reputation: 1245
I'm trying to do a cURL command in my gitlab-ci file on a Jenkins' API endpoint to start a job, but no matter what I try the second parameter always gets dropped. Here is my gitlab-ci file:
selenium_test:
stage: run_test
tags:
- autotest1
only:
- trigger
script:
- jenkins_response=$(curl -s -I -X POST http://user:token@localhost:8080/job/qTest/buildWithParameters?environment=CI%20Dev&test_id=96)
With the code above, the test_id=96
gets dropped. If I reverse the order of the parameters like so test_id=96&environment=CI%20Dev
then the environment=CI%20Dev
gets dropped.
I've also tried encoding the entire string like so environment%3DCI%20Dev%26test_id%3D96
but that didn't work either.
The two Jenkins' parameters, test_id and environment, are configured in Jenkins as strings.
Any ideas on what I'm doing wrong?
Upvotes: 1
Views: 919
Reputation: 6663
Any ideas on what I'm doing wrong?
You are not escaping shell special character (&). Consider following two snippets:
curl http://urlecho.appspot.com/echo?status=200&body=ALLOK
which will drop second argument and return None
and
curl "http://urlecho.appspot.com/echo?status=200&body=ALLOK"
which will interpret second argument and return proper ALLOK
response.
You have two options: to enclose full url in double quotes or to escape & like you did with space character in your example. Consider following suggestion from cURL documentation:
when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.
Upvotes: 2