如果在提交日志中包含明确的单词,则在cc.net上运行构建

ale*_*gin 5 svn cruisecontrol.net msbuild nunit webdriver

我有以下系统:

  • svn - 控制版
  • cc.net - 作为ci服务器
  • msbuild - 作为构建系统
  • nunit - 用于发射测试
  • webdriver - 用于网络测试.

现在我的测试在每次提交后自动运行.但是如果提交有#runautotest(或其他)注释,我希望我的测试运行.

我调查了cc.net的触发器,但它是为了另一个目标.我尝试找到一些关于cc.net解析日志的信息,但这没有积极的结果.

我应该用什么方法来解决我的问题?

Ada*_*uss 3

在 ccnet 配置中的项目中,任务块的顶部:

<modificationWriter>
 <filename>svn_mods.xml</filename>
 <path>c:\modsdir</path>
</modificationWriter>
Run Code Online (Sandbox Code Playgroud)

这会将 SVN 修改写入文件。

接下来在任务块中:

<nant>
 <executable>c:\path_to_nant</executable>
 <buildFile>mybuildfile.build</buildFile>
 <targetList>
  <target>conditionally_run_nunit_tests</target>
 </targetList>
</nant>
Run Code Online (Sandbox Code Playgroud)

这将在修改写入器任务之后运行 Nant 任务。

conditionally_run_nunit_tests中,在文件c:\modsdir\svn_mods.xml 中搜索#runautotest。如果找到它,请运行测试。如果你没有找到它,那么什么也不做。有多种方法可以解析 mods 文件。您可以使用 C# 脚本将整个文件读入字符串,然后调用 Contains 传入 #runautotest。

以下代码是在 Nant 中使用 C# 脚本的示例。SearchFile 打开一个文件,将其读入字符串并检查字符串中是否有值。它返回“是”或“否”。下面的脚本未经测试。

<property name="yesno" value="${ns::SearchFile("c:\modsdir\svn_mods.xml", "#runautotest")}"/>

<script language="c#" prefix="ns">
    <references>
        <include name="System"/>
        <include name="System.IO"/>
    </references>
    <code>
    <![CDATA[   
    [Function("SearchFile")]
    public static string SearchFile(string filepath, string token) 
    {
        System.IO.StreamReader myFile = new System.IO.StreamReader(filepath);
        string myString = myFile.ReadToEnd();
        myFile.Close();
        if(myString.Contains(token)) return "yes";
        else return "no";
    }               
    ]]>
    </code>
</script>
Run Code Online (Sandbox Code Playgroud)