[英]Convert curl with additional parameters into PHP curl
Trying to convert a curl
command for building Jenkins job
so I can use it in PHP. 尝试转换
curl
命令以构建Jenkins job
以便可以在PHP中使用它。 Here is what I do: 这是我的工作:
<?php
$testrun_id = "1744";
$cmd="curl -X POST http://build:f9280f220bfb4c596f83a0@mobile-jenkins.me.com: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
. 在这里,我传递3个参数的
jenkins job
,他们是POST_RESULTS
值为true
, RUN_ID
使用var价值$testrun_id
这是1744
和CHECK_NAME
,其值是SamplAutomatedPlan
。 When I run this curl command on mac terminal, it works perfectly fine. 当我在Mac终端上运行curl命令时,它的工作原理非常好。
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? 当我尝试运行此php脚本时,缺少的东西或给我
Parse error: parse error on that $cmd="curl..." line
?
您需要通过添加反斜杠来转义双引号。
$cmd = "curl -X POST http://build:f9280f220bfb4c596f83a0@mobile-jenkins.me.com: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\"}]}'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.