Slackbot
05/19/2022, 11:11 PMVampire
05/20/2022, 7:53 AMChris Lee
05/20/2022, 8:19 AMVampire
05/20/2022, 10:25 AMabstract class TheService : BuildService<None>, OperationCompletionListener {
init {
println(
// have an extra blank line in case the caret is not at the beginning of a line
"""
##teamcity[setParameter name='version' value='$version']
""".trimIndent()
)
}
override fun onFinish(event: FinishEvent?) {
// intentionally empty, the constructor does the work so that it is done
// as early as possible; the OperationCompletionListener is just implemented
// so that this service gets instantiated as soon as the first task finished
// if it was not created during configuration phase due to configuration cache
}
}
and something like this at configuration time:
@get:Inject
protected abstract val buildServiceRegistry: BuildServiceRegistry
@get:Inject
protected abstract val buildEventsListenerRegistry: BuildEventsListenerRegistry
private val theService: Provider<TheService> = buildServiceRegistry.registerIfAbsent(
"theService",
TheService::class.java
) {
}
init {
// if configuration phase is executed, create the service eagerly
// otherwise it is created as soon as the first task finished if run on TeamCity
theService.get()
buildEventsListenerRegistry.onTaskCompletion(theService)
}