|
CruiseControl.NET : Dynamic Parameters
This page last changed on Jan 27, 2010 by csut017.
Dynamic ParametersStarting with CruiseControl.NET 1.5.0, it is possible to define dynamic parameters for a project. These parameters are values that are set at build time, as opposed to being hard-coded within the configuration file. Defining ParametersParameters are defined at the project-level. Each parameter must be defined here - if you try to use a parameter that is not defined you will get a runtime error! The following parameters are defined: System ParametersAs well as custom parameters, a number of parameters are defined by the system. These are the same as the Integration Properties. To use one of these parameters, prefix it with a $, e.g. $CCNetBuildCondition.
Using ParametersParameters can be used for tasks/publishers, source control blocks and labellers. Using parameters can be done in one of two ways: configuration definition or implied replacement.
Configuration DefinitionIn this approach the parameter usage is defined within the configuration file. This is generally the more complex approach, but it provides better control over how the parameters are applied. To us this approach a dynamicValues element must be added to the task/publisher: <dynamicValues> <directValue> <property>buildArgs</property> <parameter>BuildArgs</parameter> <default>-t:Dev</default> </directValue> </dynamicValues> The following dynamic values are defined: Implied ReplacementIn this approach the parameters are defined inline in the properties. When the configuration is loaded, CruiseControl.NET reads these parameters and converts them into dynamicValues (as above). An inline definition is contained with a $[...] block and can consist of one or more parts seperated by pipe characters. The first part is the parameter name, the second part is the default value and the third part is the format (only used when a replacementValue is generated). If an integration property is being used, this will need to have both the $ sign for the implied replacement, plus for the integration property, e.g. $[$CCNetUser]. Some examples are:
ExamplesHere are some examples of how to use dynamic values and parameters in a project. For each example, the following basic project template is used: <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/trunk</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> </sourcecontrol> <triggers> <intervalTrigger /> </triggers> <tasks> <nant> <buildFile>App.build</buildFile> <targetList> <target>Dev</target> </targetList> <buildArgs>-D:reason=testing</buildArgs> </nant> <gendarme> <assemblies> <assemblyMatch expr="*.dll"/> </assemblies> <limit>100</limit> </gendarme> </tasks> <publishers> <rss /> <xmllogger /> </publishers> </project> Defining a Build TargetIn this example, a single select parameter is being used to set the build target. The user can choose from one of the predefined values: <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/trunk</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> </sourcecontrol> <triggers> <intervalTrigger /> </triggers> <tasks> <nant> <buildFile>App.build</buildFile> <targetList> <target>$[buildType|DEV]</target> </targetList> <buildArgs>-D:reason=testing</buildArgs> </nant> <gendarme> <assemblies> <assemblyMatch expr="*.dll"/> </assemblies> <limit>100</limit> </gendarme> </tasks> <publishers> <rss /> <xmllogger /> </publishers> <parameters> <selectParameter name="buildType"> <allowedValues> <value name="Development">DEV</value> <value name="Test">TEST</value> <value name="Production">PROD</value> </allowedValues> </selectParameter> </parameters> </project> Setting a Numeric LimitIn this example, a numeric parameter is used to limit the number of errors that is reported by then Gendarme task: <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/trunk</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> </sourcecontrol> <triggers> <intervalTrigger /> </triggers> <tasks> <nant> <buildFile>App.build</buildFile> <targetList> <target>Dev</target> </targetList> <buildArgs>-D:reason=testing</buildArgs> </nant> <gendarme> <assemblies> <assemblyMatch expr="*.dll"/> </assemblies> <limit>$[GendarmeLimit|100]</limit> </gendarme> </tasks> <publishers> <rss /> <xmllogger /> </publishers> <parameters> <numericParameter name="GendarmeLimit"> <description>The limit of Gendarme errors.</description> <minimum>50</minimum> <maximum>500</maximum> <default>100</default> </numericParameter> </parameters> </project> Configuring the Build TaskIn this example, all the values of the build task can be configured - this includes a combination of both direct and replacement dynamic values: <cruisecontrol> <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/trunk</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> </sourcecontrol> <triggers> <intervalTrigger /> </triggers> <tasks> <nant> <buildFile>$[BuildScript|App].build</buildFile> <targetList> <target>$[BuildType|DEV]</target> </targetList> <buildArgs>-D:reason=$[Reason] -D:start=$[StartDate]</buildArgs> </nant> <gendarme> <assemblies> <assemblyMatch expr="*.dll"/> </assemblies> <limit>100</limit> </gendarme> </tasks> <publishers> <rss /> <xmllogger /> </publishers> <parameters> <booleanParameter name="BuildScript"> <true name="App">Yes</true> <false name="FullBuild">No</false> <display>Production Build</display> <description>Do you want to generate a production build?</description> <default>App</default> </booleanParameter> <selectParameter name="BuildType"> <description>The type of build to perform.</description> <allowedValues> <value>Dev</value> <value>Test</value> <value>Prod</value> </allowedValues> <default>Dev</default> </selectParameter> <textParameter name="Reason"> <description>Reason for the build being forced.</description> <minimum>10</minimum> <maximum>255</maximum> <required>true</required> </textParameter> <dateParameter name="StartDate"> <default>Today</default> <minimum>1-Jan-2000</minimum> <maximum>31-Dec-2100</maximum> </dateParameter> </parameters> </project> </cruisecontrol> An alternate way of defining the last example is to explicitly define the dynamic parameters in the task: <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/trunk</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> </sourcecontrol> <triggers> <intervalTrigger /> </triggers> <tasks> <nant> <buildFile>App.build</buildFile> <targetList> <target>DEV</target> </targetList> <buildArgs>-D:reason= -D:start=</buildArgs> <dynamicValues> <replacementValue> <format>{0}.build</format> <parameters> <namedValue> <name>BuildScript</name> <value>App</value> </namedValue> </parameters> <property>buildFile</property> </replacementValue> <directValue> <default>DEV</default> <parameter>BuildType</parameter> <property>targetList/target</property> </directValue> <replacementValue> <format>-D:reason={0} -D:start={1}</format> <parameters> <namedValue> <name>Reason</name> <value /> </namedValue> <namedValue> <name>StartDate</name> <value /> </namedValue> </parameters> <property>buildArgs</property> </replacementValue> </dynamicValues> </nant> <gendarme> <assemblies> <assemblyMatch expr="*.dll"/> </assemblies> <limit>100</limit> </gendarme> </tasks> <publishers> <rss /> <xmllogger /> </publishers> <parameters> <booleanParameter name="BuildScript"> <true name="App">Yes</true> <false name="FullBuild">No</false> <display>Production Build</display> <description>Do you want to generate a production build?</description> <default>App</default> </booleanParameter> <selectParameter name="BuildType"> <description>The type of build to perform.</description> <allowedValues> <value>Dev</value> <value>Test</value> <value>Prod</value> </allowedValues> <default>Dev</default> </selectParameter> <textParameter name="Reason"> <description>Reason for the build being forced.</description> <minimum>10</minimum> <maximum>255</maximum> <required>true</required> </textParameter> <dateParameter name="StartDate"> <default>Today</default> <minimum>1-Jan-2000</minimum> <maximum>31-Dec-2100</maximum> </dateParameter> </parameters> </project> In a Source Control BlockParameters can be used within a source control block in the same way as in a task. Just remember, parameters are static within a build, they do not change after the build has been started. <project name="Test Project"> <description>A demonstration project to show the features of the dynamic build parameters.</description> <sourcecontrol xsi:type="svn"> <trunkUrl>svn://svn.mycompany.com/firstproject/$[branch|trunk]</trunkUrl> <workingDirectory>C:\SourceControl\FirstProject\</workingDirectory> <username>$[$CCNetUser|system]</username> </sourcecontrol> <tasks> <nant> <buildFile>App.build</buildFile> <targetList> <target>Dev</target> </targetList> <buildArgs>-D:reason=testing</buildArgs> </nant> </tasks> <publishers> <rss /> <xmllogger /> </publishers> <parameters> <selectParameter name="branch"> <allowedValues> <value name="trunk">trunk</value> <value name="prototype">branches/prototype</value> <value name="previous">branches/previous</value> </allowedValues> <default>trunk</default> </selectParameter> </parameters> </project> |
| Document generated by Confluence on Jan 23, 2011 08:52 |