ru.tinkoff.plugins.buildmetrics.gradle.metrics.BuildResultMetricsFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-metrics-gradle Show documentation
Show all versions of build-metrics-gradle Show documentation
Extension for tinkoff build metrics gradle plugin.
package ru.tinkoff.plugins.buildmetrics.gradle.metrics
import org.gradle.api.flow.BuildWorkResult
import ru.tinkoff.plugins.buildmetrics.api.builds.BuildWorkResultListener
import ru.tinkoff.plugins.buildmetrics.api.factories.Factory
import ru.tinkoff.plugins.buildmetrics.api.labels.Label
import ru.tinkoff.plugins.buildmetrics.api.metrics.Metric
import kotlin.jvm.optionals.getOrNull
/**
* Metrics:
* - gradle_build_success
* - gradle_build_failure - label with build error text;
*/
class BuildResultMetricsFactory : Factory.Metrics, BuildWorkResultListener {
@Transient
private var failure: String? = null
override fun reinitialize() {
failure = null
}
override fun onBuildWorkResult(result: BuildWorkResult) {
result.failure.getOrNull()?.let { buildFailure ->
failure = buildFailure.toString()
}
}
override fun create(): List> {
return listOf(
buildSuccessMetric()
)
}
private fun buildSuccessMetric(): Metric = Metric(
name = "gradle_build_success",
value = failure == null,
labels = failure?.let { buildFailure ->
listOf(Label(name = "gradle_build_failure", value = buildFailure))
} ?: emptyList()
)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy