Hello Peter,
In lieu of a Hudson plug-in (I do not know Java), how about some XSL (1.0)? In the following solution :
- We get a directory list of tags via
svn list --xml
, saved to svn-list.xml
- We run a transform to turn svn-list.xml into Hudson's internal schema for a choice drop-down, saved to hudson-list.xml
- We run another transform to join hudson-list.xml into the job's config.xml based on a specific name for the list we want to update, saved to new-config.xml, and update the Hudson job with the new config
1. svn list --xml
svn list [path-to-svn-tag-directory] --xml > svn-list.xml
2. Convert SVN list to Hudson list
xsltproc svn-to-hudson.xsl svn-list.xml > hudson-list.xml
svn-to-hudson.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/lists/list">
<hudson.model.ChoiceParameterDefinition>
<name>[Your Name for the List]</name>
<description/>
<choices class="java.util.Arrays$ArrayList">
<a class="string-array">
<xsl:apply-templates select="entry"/>
</a>
</choices>
</hudson.model.ChoiceParameterDefinition>
</xsl:template>
<xsl:template match="entry">
<string>
<xsl:value-of select="name"/>
</string>
</xsl:template>
</xsl:stylesheet>
3. Join Hudson List with Job's config.xml
The following uses curl
to get fetch the old config.xml, and to post the new one, utilizing Hudson's job API for modifying the config.
curl -o old-config.xml http://[your-hudson-server]/job/[job-name]/config.xml -u [username]:[password]
xsltproc join.xsl old-config.xml > new-config.xml
curl -X POST -d @new-config.xml http://[your-hudson-server]/job/[job-name]/config.xml -u [username]:[password]
join.xsl requires the presence of hudson-list.xml in the same directory:
<xsl:variable name="tag-list" select="document('hudson-list.xml')"/>
You will also need to modify
<xsl:variable name="list-name" select="string('Name')"/>
to the name of your list in the job (e.g., 'SVN tags', 'Tagged Builds', etc...).
join.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="tag-list" select="document('hudson-list.xml')"/>
<xsl:variable name="list-name" select="string('Name')"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="hudson.model.ChoiceParameterDefinition">
<xsl:choose>
<xsl:when test="name = $list-name"> <!-- If the name matches, swap in new list -->
<xsl:copy-of select="$tag-list"/>
</xsl:when>
<xsl:otherwise> <!-- If the name does not match, copy what's already there -->
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
I hope this end-to-end solution works for you.
Thank you,
Zachary