PHP cURL POST Jenkins使用参数 [英] PHP cURL POST Jenkins job with parameters
问题描述
通过以下 PHP
脚本触发 Jenkins工作
:
<?php
$testrun_id = "1744";
$cmd = "curl -X POST http://build:f9280f75396f83a0@mobile-jenkins.domain.com:8080/job/android-test/build --data-urlencode json='{\"parameter\": [{\"name\":\"POST_RESULTS\", \"value\":\"true\"}, {\"name\":\"RUN_ID\", \"value\":\"{$testrun_id}\"}, {\"name\":\"CHECK_NAME\", \"value\":\"SampleAutomatedPlan\"}]}'";
exec($cmd,$result);
?>
此脚本在 Mac 上成功运行,jenkins作业被触发。如何让此脚本在 Windows 上运行?我在 Windows 上运行PHP脚本时遇到以下错误?
This script runs successfully on Mac and the jenkins job does get triggered. How do I make this script to work on Windows? I am getting following error when I run above PHP script on Windows?
curl is已安装在Windows机器上
。此外,有没有更好的方法来做PHP的PHP?看看这个: http://php.net/manual/en/book.curl。 php ,有人可以指向我在上述PHP脚本( Windows )中基于我的curl命令的示例?
curl is already installed on windows machine
. Also, is there a better way to do cURL in PHP? Looking at this: http://php.net/manual/en/book.curl.php, can someone point me towards an example based on my curl command in the above PHP script(for Windows)? An example based on the curl command in my script would be ideal.
推荐答案
你应该检查这里的例子 http://php.net/manual/en/curl.examples.php
you should check examples from here http://php.net/manual/en/curl.examples.php
Bellow是您的代码,
Bellow is the code for you case,
$url = "http://build:f9280f75396f83a0@mobile-jenkins.domain.com:8080/job/android-test/buildWithParameters";
$data = "POST_RESULTS=true&RUN_ID=".$testrun_id."&CHECK_NAME=SampleAutomatedPlan";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
这篇关于PHP cURL POST Jenkins使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!