schema for hudson job config.xml

1.2k Views Asked by At

am new to HUDSON ci-server . i have a requirement stating that i have to use Hudson remote access API and create new jobs in hudson or edit the existing job's configuration file and update it.

I have a sample config.xml file .

<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>Free style Basic sample Job for POC . will create this job with all the required fields . then will take this config.xml and will try to validate and study this schema .</description>
<project-properties class="java.util.concurrent.ConcurrentHashMap">
<entry>
  <string>hudson-plugins-disk_usage-DiskUsageProperty</string>
  <base-property>
    <originalValue class="hudson.plugins.disk_usage.DiskUsageProperty"/>
    <propertyOverridden>false</propertyOverridden>
  </base-property>
</entry>
<entry>
  <string>logRotator</string>
  <log-rotator-property>
    <originalValue class="hudson.tasks.LogRotator">
      <daysToKeep>5</daysToKeep>
      <numToKeep>-1</numToKeep>
      <artifactDaysToKeep>-1</artifactDaysToKeep>
      <artifactNumToKeep>-1</artifactNumToKeep>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
  </log-rotator-property>
</entry>
<entry>
  <string>scmCheckoutRetryCount</string>
  <integer-property>
    <originalValue class="int">5</originalValue>
    <propertyOverridden>false</propertyOverridden>
  </integer-property>
</entry>
<entry>
  <string>hudson-tasks-Mailer</string>
  <external-property>
    <originalValue class="hudson.tasks.Mailer">
      <recipients>[email protected]</recipients>
      <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
      <sendToIndividuals>false</sendToIndividuals>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
    <modified>true</modified>
  </external-property>
</entry>
<entry>
  <string>hudson-plugins-build_timeout-BuildTimeoutWrapper</string>
  <external-property>
    <originalValue class="hudson.plugins.build_timeout.BuildTimeoutWrapper">
      <timeoutMinutes>5</timeoutMinutes>
      <failBuild>false</failBuild>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
    <modified>true</modified>
  </external-property>
</entry>
<entry>
  <string>builders</string>
  <describable-list-property>
    <originalValue class="hudson.util.DescribableList">
      <hudson.tasks.Ant>
        <targets></targets>
        <antName>org.apache.ant_1.7.1</antName>
      </hudson.tasks.Ant>
      <hudson.tasks.Shell>
        <command>HUDSON_USER</command>
      </hudson.tasks.Shell>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
  </describable-list-property>
</entry>
<entry>
  <string>hudson-triggers-SCMTrigger</string>
  <trigger-property>
    <originalValue class="hudson.triggers.SCMTrigger">
      <spec>@daily</spec>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
  </trigger-property>
</entry>
<entry>
  <string>jdk</string>
  <string-property>
    <originalValue class="string">(Inherit From Job)</originalValue>
    <propertyOverridden>false</propertyOverridden>
  </string-property>
</entry>
<entry>
  <string>hudson-tasks-ArtifactArchiver</string>
  <external-property>
    <originalValue class="hudson.tasks.ArtifactArchiver">
      <compressionType>GZIP</compressionType>
      <latestOnly>false</latestOnly>
      <autoValidateFileMask>false</autoValidateFileMask>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
    <modified>true</modified>
  </external-property>
</entry>
<entry>
  <string>scm</string>
  <scm-property>
    <originalValue class="hudson.scm.NullSCM"/>
    <propertyOverridden>false</propertyOverridden>
  </scm-property>
</entry>
<entry>
  <string>hudson-plugins-release-ReleaseWrapper</string>
  <external-property>
    <originalValue class="hudson.plugins.release.ReleaseWrapper">
      <releaseVersionTemplate></releaseVersionTemplate>
      <doNotKeepLog>false</doNotKeepLog>
      <overrideBuildParameters>false</overrideBuildParameters>
      <parameterDefinitions/>
      <preBuildSteps/>
      <postBuildSteps/>
      <postSuccessfulBuildSteps/>
      <postFailedBuildSteps/>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
    <modified>true</modified>
  </external-property>
</entry>
</project-properties>
 <keepDependencies>false</keepDependencies>
<creationTime>1403865219075</creationTime>
 <properties/>
     <cascadingChildrenNames class="java.util.concurrent.CopyOnWriteArraySet"/>
     <cascading-job-properties class="java.util.concurrent.CopyOnWriteArraySet">
    <string>hudson-plugins-batch_task-BatchTaskProperty</string>
  <string>hudson-plugins-disk_usage-DiskUsageProperty</string>
  <string>hudson-plugins-jira-JiraProjectProperty</string>
  <string>org-hudsonci-plugins-snapshotmonitor-WatchedDependenciesProperty</string>
  <string>hudson-plugins-promoted_builds-JobPropertyImpl</string>
   </cascading-job-properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>false</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <concurrentBuild>false</concurrentBuild>
  <cleanWorkspaceRequired>false</cleanWorkspaceRequired>
 </project>

Now i have a tag called project-properties . in it i have multiple entry tags .each enrty tag has some sub tags among which string is common to each entry tag .I want to access all these different tags through java using Hudosn remote access API .

for example :

<entry>
      <string>logRotator</string>
      <log-rotator-property>
      <originalValue class="hudson.tasks.LogRotator">
      <daysToKeep>5</daysToKeep>
      <numToKeep>-1</numToKeep>
      <artifactDaysToKeep>-1</artifactDaysToKeep>
      <artifactNumToKeep>-1</artifactNumToKeep>
    </originalValue>
    <propertyOverridden>false</propertyOverridden>
  </log-rotator-property>
</entry>

so i want to acceess daysToKeep numToKeep artifactDaysToKeep and so on for the rest of tags and other tags present in the config.xml

Any help will be appreciated. Thanks in advance.

1

There are 1 best solutions below

0
code-a-doodle-do On

You could do this by getting an instance of the Item and then updating the project configuration by using the following code

Source streamSource = new StreamSource(new StringReader(config));
    try {
        proj.updateByXml(streamSource);

    } catch (IOException ex) {
        Logger.getLogger(PluginImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

the config is the string generated config file.

For more info refer to this post How to update Jenkins config.xml from Java code?