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 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?