How to maneuver templates behaviors

Answered

I'm struggling with a problem, I have a template that is inherited by lots of BuildTypes (or other classes/template), this template contains some common tasks but sometimes tasks are not needed or have to be changed in their parameters. There is a way to pilot the template behavior from the inheriting class?

Below an example:

open class MyBaseClass : MyStandardBaseClass() {
init {
steps {}
triggers {}
failureConditions {
failOnMetricChange {
id = "someFailureOnMetricChange"
threshold = 1 // I would like to dynamically change this
units = BuildFailureOnMetric.MetricUnit.DEFAULT_UNIT
comparison = BuildFailureOnMetric.MetricComparison.DIFF
compareTo = value()
param("metricKey", "MyKey")
param("anchorBuild", "lastSuccessful")
}
}
}
}

object MyBaseTemplate : MyBaseClass() {
init {
name = "MyBaseTemplate"
id = "My Template for something"
}
}

object MyBuildType : BuildType({
templates(myBuildTypes.templates.MyBaseClassTemplate)
// for this build type I need the threshold in someFailureOnMetricChange set at 1
}

object MyOtherBuildType : BuildType({
templates(myBuildTypes.templates.MyBaseClassTemplate)
// for this build type I need the threshold in someFailureOnMetricChange set at 100
}
0
2 comments

Hi,

You can parametrize the threshold and give the parameter different values in different build configurations. Would that help in your use case?

-Anatoly 

0
Avatar
Permanently deleted user

perhaps I did something wrong but I tried this path but it seems it works if I extend a class but not if I'm using templates, templates apply objects masks to the caller class.

I tried also adding some myTestVar in the 

object SoftwareUpdates : Project(
{
id("N2OSPipelineDSL_SoftwareUpdates")
name="Software Updates"
template(myBuild.templates.MyBaseClass)
subProject(myBuild.someProject.MyBuildType)
}
) {
var myTestVar: Int = 123
}

but it works if I call the myTestVar on MyStandarBaseClass but I got an error if I try to set some different value in BuildTypes

0

Please sign in to leave a comment.