我已经为我的项目设置了 Cruisecontrol 构建,我需要在多个环境中运行它。这是我目前使用的:
<parameters>
<selectParameter>
<name>Environment1</name>
<display>Environment1</display>
<allowedValues>
<value name="No">No</value>
<value name="Yes">Yes</value>
</allowedValues>
</selectParameter>
<selectParameter>
<name>Environment2</name>
<display>Environment2</display>
<allowedValues>
<value name="No">No</value>
<value name="Yes">Yes</value>
</allowedValues>
</selectParameter>
<selectParameter>
<name>Environment3</name>
<display>Environment3</display>
<allowedValues>
<value name="No">No</value>
<value name="Yes">Yes</value>
</allowedValues>
</selectParameter>
</parameters>
<conditional>
<conditions>
<compareCondition value1="Environment1" evaluation="equal" value2="Yes" />
</conditions>
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirectory>$[DirectoryOfBuildScript]</workingDirectory>
<projectFile>MSBuild.proj</projectFile>
<buildArgs>/v:n /p:Environment=Environment1;Version=$[BuildVersion];</buildArgs>
<targets>Deploy</targets>
<timeout>3000</timeout>
<logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
</conditional>
<conditional>
<conditions>
<compareCondition value1="Environment2" evaluation="equal" value2="Yes" />
</conditions>
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirectory>$[DirectoryOfBuildScript]</workingDirectory>
<projectFile>MSBuild.proj</projectFile>
<buildArgs>/v:n /p:Environment=Environment2;Version=$[BuildVersion];</buildArgs>
<targets>Deploy</targets>
<timeout>3000</timeout>
<logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
</conditional>
<conditional>
<conditions>
<compareCondition value1="Environment3" evaluation="equal" value2="Yes" />
</conditions>
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirectory>$[DirectoryOfBuildScript]</workingDirectory>
<projectFile>MSBuild.proj</projectFile>
<buildArgs>/v:n /p:Environment=Environment3;Version=$[BuildVersion];</buildArgs>
<targets>Deploy</targets>
<timeout>3000</timeout>
<logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
</conditional>
如您所见,所有条件语句中只有环境名称不同。有什么方法可以通过循环选择的环境名称来概括我的构建调用(版本不会有所不同)。像这样的东西:
// Conceptually I want a for loop which iterates through the selected environments
foreach(environmentName in selectedEnvironments)
{
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirectory>$[DirectoryOfBuildScript]</workingDirectory>
<projectFile>MSBuild.proj</projectFile>
<buildArgs>/v:n /p:Environment=environmentName;Version=$[BuildVersion];</buildArgs>
<targets>Deploy</targets>
<timeout>3000</timeout>
<logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
}