Reputation: 299
Trying to convert a curl
command for building Jenkins job
so I can use it in PHP. Here is what I do:
<?php
$testrun_id = "1744";
$cmd="curl -X POST http://build:[email protected]:8080/job/android-job-git/build --data-urlencode json='{"parameter": [{"name":"POST_RESULTS", "value":"true"}, {"name":"RUN_ID", "value":"{$testrun_id}"}, {"name":"CHECK_NAME", "value":"SampleAutomatedPlan"}]}'";
exec($cmd, $result);
?>
Here I am passing 3 parameters to the jenkins job
and they are POST_RESULTS
with value true
, RUN_ID
with value of var $testrun_id
which is 1744
and CHECK_NAME
whose value is SamplAutomatedPlan
. When I run this curl command on mac terminal, it works perfectly fine.
What would be the missing things OR errors that gives me Parse error: parse error on that $cmd="curl..." line
when I try to run this php script?
Upvotes: 1
Views: 185
Reputation: 4089
You need to escape the double quotes by adding backslashes.
$cmd = "curl -X POST http://build:[email protected]:8080/job/android-job-git/build --data-urlencode json='{\"parameter\": [{\"name\":\"POST_RESULTS\", \"value\":\"true\"}, {\"name\":\"RUN_ID\", \"value\":\"{$testrun_id}\"}, {\"name\":\"CHECK_NAME\", \"value\":\"SampleAutomatedPlan\"}]}'";
Upvotes: 2