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>abc#example.com</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.
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?
Related
I have an xml string in the following format
<map>
<entry>
<string>key</string>
<string>value</string>
</entry>
<entry>
<string>key2</string>
<string>value2</string>
</entry>
....
</map>
Is there an easy library/tool that I can use to read this type of xml directly into a Hashmap. I am not very familiar with working with xml, so I would really appreciate some help here.
Thanks.
I am trying to make an xsd file out of a json response that I have got and later using that xsd to generate JAXB classes. My problem is that the json is in a format I am unable to convert to xsd. Here is my json :
{
"result1":[{"010201":[3,2,0,4,3,4]},{"010202":[1,6,3,2,2,2]},{"010203":[2,3,3,4,4,0]}],
"result2":[1,6,3,2,2,2],
"result3":[{"010201":[3,2,0,3,4]},{"010202":[1,6,3,2,2]},{"010203":[2,3,4,4,0]}],
"result4":[1,4,6,4,1],
"result5":[{"010201":34},{"010202":12},{"010203":78}],
"result6":41
}
Here is the above json in xml format :
<?xml version="1.0" encoding="UTF-8" ?>
<result1>
<010201>3</010201>
<010201>2</010201>
<010201>0</010201>
<010201>4</010201>
<010201>3</010201>
<010201>4</010201>
</result1>
<result1>
<010202>1</010202>
<010202>6</010202>
<010202>3</010202>
<010202>2</010202>
<010202>2</010202>
<010202>2</010202>
</result1>
<result1>
<010203>2</010203>
<010203>3</010203>
<010203>3</010203>
<010203>4</010203>
<010203>4</010203>
<010203>0</010203>
</result1>
<result2>1</result2>
<result2>6</result2>
<result2>3</result2>
<result2>2</result2>
<result2>2</result2>
<result2>2</result2>
<result3>
<010201>3</010201>
<010201>2</010201>
<010201>0</010201>
<010201>3</010201>
<010201>4</010201>
</result3>
<result3>
<010202>1</010202>
<010202>6</010202>
<010202>3</010202>
<010202>2</010202>
<010202>2</010202>
</result3>
<result3>
<010203>2</010203>
<010203>3</010203>
<010203>4</010203>
<010203>4</010203>
<010203>0</010203>
</result3>
<result4>1</result4>
<result4>4</result4>
<result4>6</result4>
<result4>4</result4>
<result4>1</result4>
<result5>
<010201>34</010201>
</result5>
<result5>
<010202>12</010202>
</result5>
<result5>
<010203>78</010203>
</result5>
<result6>41</result6>
I am facing no issues in creating complex types for result2, result4, result6 elements. But result1, result3 and result5 have an array of array of integers. How do i create an xsd for that ? Can anyone help ?
Consider trying an XSD to generate an XML like the below:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<result1>
<entry>
<key>010201</key>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</entry>
<entry>
<key>010201</key>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</entry>
</result1>
<result2>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</result2>
<result3>
<entry>
<key>010201</key>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</entry>
<entry>
<key>010201</key>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</entry>
</result3>
<result4>
<value>
<val>3</val>
<val>2</val>
<val>1</val>
</value>
</result4>
<result5>
<entry>
<key>010201</key>
<value>2</value>
</entry>
<entry>
<key>010201</key>
<value>2</value>
</entry>
</result5>
</root>
The xsd will be simpler for the above. Keeping the values as XML tags will not be feasible if the values will change.
Anyone could tell me how to Serialize a HashMap with XStream?
private HashMap<String,String> attributes;
attributes = new HashMap<String,String>();
attributes.put("Description","Value");
attributes.put("Description2","Value2");
attributes.put("Description3","Value3");
My xml looks like
<attributes>
<entry>
<string>Description</string>
<string>value</string>
</entry>
<entry>
<string>Description2</string>
<string>Value2</string>
</entry>
<entry>
<string>Description3</string>
<string>Value3</string>
</entry>
</attributes>
I want an output like
<attributes>
<attr>
<description>Description</description>
<value>Value</value>
</attr>
<attr>
<description>Description2</description>
<value>Value2</value>
</attr>
<attr>
<description>Description3</description>
<value>Value</value>
</attr>
</attributes>
how can achieve that using XStream? Is possible with annotations?
If you are using XStream 1.4.5, you have the NamedMapConverter to do what you want.
Just register the converter showing how you want to marshal your map as the example bellow:
XStream xstream = new XStream();
NamedMapConverter namedMapConverter = new NamedMapConverter(xstream.getMapper(),"attr","description",String.class,"value",String.class);
xstream.registerConverter(namedMapConverter);
Event provider HudsonTracPlugin failed for filters "Hudson Builds": IOError: Error getting build info from:
'http://localhost:8080/hudson/rssAll/api/python?tree=jobs[builds[building,timestamp,duration,result,description,url,fullDisplayName]]': URLError: <urlopen error [Errno 10061] >.
This most likely means you configured a wrong job_url, username, or password.
Event provider HudsonTracPlugin failed for filters "Hudson Builds": IOError: Error getting build info from 'http://localhost:8080/hudson/rssAll/api/python?tree=jobs[builds[building,timestamp,duration,result,description,url,fullDisplayName]]': returned document has unexpected type 'application/atom+xml' (expected 'text/x-python'). The returned text is: <?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>All all builds</title>
<link type="text/html" href="http://localhost:8080/hudson/" rel="alternate"/>
<updated>2013-01-04T09:04:56Z</updated>
<author>
<name>Hudson Server</name>
</author>
<id>urn:uuid:903deee0-7bfa-11db-9fe1-0800200c9a66</id>
<entry>
<title>tractest12github #9 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/9/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-04_18-04-56</id>
<published>2013-01-04T09:04:56Z</published>
<updated>2013-01-04T09:04:56Z</updated>
</entry>
<entry>
<title>tractest #6 (stable)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest/6/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest:2013-01-04_18-04-50</id>
<published>2013-01-04T09:04:50Z</published>
<updated>2013-01-04T09:04:50Z</updated>
</entry>
<entry>
<title>tractest12github #8 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/8/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-04_17-52-54</id>
<published>2013-01-04T08:52:54Z</published>
<updated>2013-01-04T08:52:54Z</updated>
</entry>
<entry>
<title>tractest #5 (stable)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest/5/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest:2013-01-04_17-52-53</id>
<published>2013-01-04T08:52:53Z</published>
<updated>2013-01-04T08:52:53Z</updated>
</entry>
<entry>
<title>tractest12github #7 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/7/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-04_17-52-06</id>
<published>2013-01-04T08:52:06Z</published>
<updated>2013-01-04T08:52:06Z</updated>
</entry>
<entry>
<title>tractest12github #6 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/6/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-04_17-51-52</id>
<published>2013-01-04T08:51:52Z</published>
<updated>2013-01-04T08:51:52Z</updated>
</entry>
<entry>
<title>tractest12github #5 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/5/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-04_17-51-03</id>
<published>2013-01-04T08:51:03Z</published>
<updated>2013-01-04T08:51:03Z</updated>
</entry>
<entry>
<title>tractest #4 (stable)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest/4/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest:2013-01-04_17-50-58</id>
<published>2013-01-04T08:50:58Z</published>
<updated>2013-01-04T08:50:58Z</updated>
</entry>
<entry>
<title>tractest #3 (stable)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest/3/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest:2013-01-04_17-50-55</id>
<published>2013-01-04T08:50:55Z</published>
<updated>2013-01-04T08:50:55Z</updated>
</entry>
<entry>
<title>tractest12github #4 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/4/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-03_17-53-04</id>
<published>2013-01-03T08:53:04Z</published>
<updated>2013-01-03T08:53:04Z</updated>
</entry>
<entry>
<title>tractest #2 (stable)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest/2/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest:2013-01-03_15-54-59</id>
<published>2013-01-03T06:54:59Z</published>
<updated>2013-01-03T06:54:59Z</updated>
</entry>
<entry>
<title>tractest12github #3 (broken for a long time)</title>
<link type="text/html" href="http://localhost:8080/hudson/job/tractest12github/3/" rel="alternate"/><id>tag:hudson.java.net,2013:tractest12github:2013-01-03_15-54-50</id>
<published>2013-01-03T06:54:50Z</published>
<updated>2013-01-03T06:54:50Z</updated>
</entry>
</feed>
Hudson3-3-0
Trac 1.0
HudsonTrac-0.5-py2.7
Window7 64
What is your question? You'll need to provide more information and some context before we can help you. An error message alone isn't enough information to figure out your problem. What were you doing when the problem happened? Did this work in the past? Has anything been changed/upgraded recently?
From what I'm guessing you're asking, you may find the discussion in this trac-hacks ticket useful: Ticket #7340 - Authentication failing.
Also, doublecheck your plugin setup and verify that all of your parameters are set correctly (especially 'job_url'). The error looks like it's getting an RSS feed instead of some other format. Your URL has "/rssAll/" in it, so it makes sense that you're getting an RSS feed. Chances are, your job_url is wrong. See the official HudsonTrac documentation for details about how to configure the plugin.
I'd like to unmarshal the following xml to a MultiKeyMap:
<map>
<entry key1="foo" key2="foo">
<value property="val"/>
</entry>
<entry key1="bar" key2="bar">
<value property="val"/>
</entry>
</map>
I took a look through the Castor API and saw that there's a CollectionFieldHandler class, but I can't find any documentation on where I would need to register a custom collection handler.
First of all, collection isn't a map.
You can implement and register your own handler.
See http://www.castor.org/xml-fieldhandlers.html