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