dte29947 2014-12-21 09:49
浏览 91

如何在Php中进行curl触发并将文件发送到jenkins作业(接受文件作为参数)

I have to trigger a job on jenkins and upload the file at same time (Jenkins has file parameter set) from PhP page.

I know we can easily do this with curl unix command specified in jenkins Remote Access API. but I want to use php curl to trigger the job at same time upload the file.

I have written following code but it doesn't work .

<?php 
   $baseUrl="197.10.2.1:8080";
   $jobName="exampledatacopy";
   $json='{"parameter": [{"name":" /var/lib/jenkins/file/workspace/1.txt", "file":"@/home/kark/Desktop/1.txt"}]}'; 
   sprintf('%s/job/%s/buildWithParameters', $baseUrl, $jobName);
   $curl = curl_init($baseUrl);
   curl_setopt($curl, CURLOPT_POST, 1);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
   curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
   $response=curl_exec($curl);
   curl_close($curl);
?>   

above code successfully triggers the job on Jenkins. Output of the job is as follows.

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/file/workspace
Finished: SUCCESS

but file is not uploaded. $response prints a response showing status of all jobs

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题