Reputation: 3502
I am attempting to create a job in using Jenkin's API. It is creating the job, but not using the parameters specified in the XML.
In this case, MyJob is created but it doesn't have the TEST_PARAM when I view the job. I have to manually create it.
This XML is mostly from an existing job, but with modified parameters.
PHP Code:
$url = 'https://jenkins_url.com/createItem?name=MyJob';
$file = '<?xml version="1.0" encoding="UTF-8"?>
<project>
<actions />
<description></description>
<logRotator class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>20</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>-1</artifactNumToKeep>
</logRotator>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<hudson.model.StringParameterDefinition>
<name>TEST_PARAM</name>
<description />
<defaultValue></defaultValue>
</hudson.model.StringParameterDefinition>
</hudson.model.ParametersDefinitionProperty>
<com.sonyericsson.rebuild.RebuildSettings
plugin="[email protected]">
<autoRebuild>false</autoRebuild>
</com.sonyericsson.rebuild.RebuildSettings>
</properties>
<scm class="hudson.scm.NullSCM" />
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<authToken>12345678910</authToken>
<triggers />
<concurrentBuild>false</concurrentBuild>
<builders />
<publishers />
<buildWrappers />
</project>';
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl_handle,CURLOPT_POST,1);
curl_setopt($curl_handle,CURLOPT_POSTFIELDS, $file);
curl_setopt($curl_handle,CURLOPT_USERPWD, "user:pass");
curl_setopt($curl_handle,CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
$buffer = curl_exec($curl_handle);
print_r(curl_getinfo($curl_handle));
curl_close($curl_handle);
print_r($buffer);
Upvotes: 1
Views: 61
Reputation: 15982
Looking at the config.xml from a job with parameters shows that your XML file is a little different compared to my output on Jenkins 1.565.3.
Try wrapping your parameters with parameterDefinitions
(inside the ParametersDefinitionProperty
element):
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>TEST_PARAM</name>
<description />
<defaultValue></defaultValue>
</hudson.model.StringParameterDefinition>
<!-- more parameters go here -->
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
...
Upvotes: 2