需要自定义构建标签器。Perforce是我们的源代码控制提供商,我们从中获取版本号。代码如下:
[ReflectorType( "p4labeller" )]
public class PerforceLabeller : ILabeller
{
[ReflectorProperty("executable", Required = false)]
public string P4Executable = "p4.exe";
[ReflectorProperty("port", Required = false)]
public string P4Port = String.Empty;
[ReflectorProperty("user", Required = false)]
public string P4User = String.Empty;
[ReflectorProperty("client", Required = false)]
public string P4Client = String.Empty;
[ReflectorProperty("view", Required = false)]
public string P4View = String.Empty;
public string Generate( IIntegrationResult previousLabel )
{
return GetLatestChangelist();
}
public void Run( IIntegrationResult result )
{
result.Label = GetLatestChangelist();
}
public string GetLatestChangelist()
{
string theArgs = "-p " + P4Port + " -u " + P4User + " -c " + P4Client + " changes -m 1 -s submitted " + P4View;
Log.Info( string.Format( "Getting latest change from Perforce using --> " + theArgs ) );
ProcessResult theProcessResult = new ProcessExecutor().Execute( new ProcessInfo( P4Executable, theArgs ) );
Regex theRegex = new Regex( @"\s[0-9]+\s", RegexOptions.IgnoreCase );
Match theMatch = theRegex.Match( theProcessResult.StandardOutput );
return theMatch.Value.Trim();
}
}
方法
GetLatestChangelist是您可能要插入自己的逻辑来与版本控制系统交互的地方。在Perforce中,有最后一个唯一的更改列表的概念。我们的构建号码,最终版本号码都是基于它。
一旦您将其构建为程序集dll,就必须将其钩入ccnet。您只需将程序集放入服务器目录(ccnet.exe旁边)。
接下来,您需要修改ccnet项目文件以利用此标签器。我们使用
默认标签器块进行了此操作。类似以下内容:
<project>
<labeller type="p4labeller">
<client>myclient</client>
<executable>p4.exe</executable>
<port>myserver:1234</port>
<user>myuser</user>
<view>//Code1/...</view>
</labeller>
<!-- Other project configuration to go here -->
</project>
如果你只是想让构建编号显示在ccnet中,那么你已经完成了,不需要做其他任何事情。然而,如果你希望在NAnt脚本中访问标签,可以使用已提供的CCNetLabel属性。
希望这能帮到你。如果你有任何问题,请在评论区留言告诉我。