When we define a template, we specify the parameters it has. Inside of the templates, we use the parameters[] notation to reference these. We can possibly validate that each referenced parameter has been defined.
Example:
class InstallDotNetTemplate : StepTemplateDefinition
{
public override string TargetFile => "templates/build-csproj.yml";
public override List<TemplateParameter> Parameters => new()
{
StringParameter("project"),
StringParameter("version", allowedValues: new[] { "5.0.100", "6.0.302" }),
};
public override ConditionedList<Step> Definition => new()
{
DotNet.Install.Sdk(parameters["version"]),
If.Equal(parameters["restore"], "true") <--- Exception "Parameter `restore` not specified"
.Step(DotNet.Restore.Projects(parameters["project"])),
DotNet.Build(parameters["project"]),
};
}
When we define a template, we specify the parameters it has. Inside of the templates, we use the
parameters[]
notation to reference these. We can possibly validate that each referenced parameter has been defined.Example: