更新 01:
这现在是 Subversion Plugin 的一部分,随 jenkins/hudson.war 一起提供。
代替 Hudson 插件(我不懂 Java),用一些 XSL (1.0) 怎么样?在以下解决方案中:
- 我们通过
svn list --xml得到标签的目录列表,保存到svn-list.xml
- 我们运行转换以将 svn-list.xml 转换为 Hudson 的内部模式,以供选择下拉菜单,保存到 hudson-list.xml
- 我们运行另一个转换以根据我们要更新的列表的特定名称将 hudson-list.xml 加入作业的 config.xml,保存到 new-config.xml,并使用新配置更新 Hudson 作业
1. svn list --xml
svn list [path-to-svn-tag-directory] --xml > svn-list.xml
2。将 SVN 列表转换为 Hudson 列表
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.使用 Job 的 config.xml 加入 Hudson List
以下使用curl 获取旧的config.xml,并发布新的,利用Hudson 的作业API 修改配置。
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 要求同一目录中存在 hudson-list.xml:
<xsl:variable name="tag-list" select="document('hudson-list.xml')"/>
你还需要修改
<xsl:variable name="list-name" select="string('Name')"/>
添加到您在工作中的列表名称(例如,“SVN 标签”、“Tagged Builds”等...)。
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>
我希望这个端到端的解决方案对你有用。
谢谢你,
扎卡里