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
}
Please sign in to leave a comment.
Hi,
You can parametrize the threshold and give the parameter different values in different build configurations. Would that help in your use case?
-Anatoly
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
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