在 Hudson我们有一个将指定的 subversion 标签部署到服务器的作业。这个标签当前是在一个文本字段中输入的,但由于这只是一个等待发生的输入错误,我们希望该文本字段被一个带有当前可用标签的下拉列表替换。也就是说,我们希望 Hudson 转到
我已经搜索了 Hudson plugin或其他一些方法来实现这一点,但没有成功。这不会是第一次有人想要这个吧?或者出于某种我目前无法想到的原因,这会被认为是不好的做法吗?
编辑
其他人确实有同样的想法(仅在三周前),但现在没有发布解决方案:http://issues.hudson-ci.org/browse/HUDSON-6682?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
编辑 2
我现在已经实现了 Zachary Young 的答案,并且在对我们的环境进行了一些修改后,它可以完美运行。
我们的修改:
我们有以 UTF-8 编码的国际内容,我不得不将其添加到 join.xsl:<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
以及上传新配置的 curl 命令:curl -H "Content-Type: text/xml; charset=UTF-8" -X POST --data-binary @$WORKING_DIR/new-config.xml $HUDSON_CONFIG_PATH -u $USER:$PASSWORD
至少我现在记得是这样。
它现在放在一个外部脚本中,但我会将它放在 Hudson 作业中,以便其他开发人员可以轻松运行它。
恳请大家赞成 Zachary Young 的回答 !
最佳答案
更新 01:
这现在是 Subversion Plugin 的一部分随附 jenkins/hudson.war
.
代替 Hudson 插件(我不懂 Java),来一些 XSL (1.0) 怎么样?在以下解决方案中:
svn list --xml
获得标签目录列表, 保存到 svn-list.xml 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 到 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 标记”、“标记的构建”等)。
加入.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>
我希望这个端到端的解决方案适合你。
谢谢,
扎卡里
关于svn - 是否有用于在 Hudson 中列出 subversion 标签的插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3102065/