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 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?