如何在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

douke1891
douke1891 除了它没有出现在Jenkins上之外,请说明它是如何工作的。它会完全执行,还是会出现错误?如果没有错误,获得的$response代码是什么?这些都与您的问题相关,如果没有这些问题,回答真的很难。
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问