Teamcity DSL - Env Parameters as Singleton

My exposure to Kotlin is via Teamcity DSL. I hope the questions are the on-topic here. If not, please let me know.

This article on DSL refactoring advises that teamcity parameters can be moved to a Kotlin Singleton - Kotlin DSL for Beginners: Recommended Refactorings | The TeamCity Blog

I have some parameters which are set and used as environment variables. How can I refactor them to Kotlin singletons and use them from environment variables

params {
   param("env.NOTARIZE_MAC_BUILD_DIR", "/Users/apple/build")
   param("env.NOTARIZE_MAC_GON_PATH", "/Users/apple/bin/gon")

The example uses a parameter with a small set of possible values which is best represented as an enum in Kotlin.

For an example that will better match what you are looking for:


enum class DockerImagePostfix {
namesAndTags = "myName-${DockerImagePostfix.STAGING}:latest" 

with just a val on its own

val dockerImagePostfix = "STAGING"
namesAndTags = "myName-$dockerImagePostfix:latest" 

or values grouped into an object (Kotlin’s singleton):

object DockerImage {
    const val POSTFIX = "STAGING"
namesAndTags = "myName-${DockerImage.POSTFIX}:latest" 

Note: If you are wondering about the casing, Kotlin constants are UPPER_CASE with underlines and other properties are camelCase by convention but it’s only a convention, it has no behavior impact.