0

I've extracted my Teamcity builds as Kotlin outputs. I want to create a base class that defines a number of common steps/settings, but allow individual builds to extend these properties.

e.g.

open class BuildBase(init: BuildBase.() -> Unit) : BuildType({
    steps {
        powerShell {
            name = "Write First Message"
            id = "RUNNER_FirstMessage"
            scriptMode = script {
                content = """
                    Write-Host "First Message"
                """.trimIndent()
            }
        }
    }
})

object Mybuild : BuildBase({
    steps { // This would add a new step to the list, without wiping out the original step
        powerShell {
            name = "Write Last Message"
            id = "RUNNER_LastMessage"
            scriptMode = script {
                content = """
                    Write-Host "Last Message"
                """.trimIndent()
            }
        }
    }
})

In this example, I want to inherit the step from the base class, but add additional steps relevant to the specific build. Additionally, I'd want to inherit the base disableSettings (if any) and disable other steps.

Is this even possible? if so, how would I go about structuring the classes to enable it?

Obsidian Phoenix
  • 4,083
  • 1
  • 22
  • 60

1 Answers1

1

You might have found a solution already but here's how I would solve your problem.

Like in the GUI, TeamCity supports build templates. In your case you would have a template like following:

object MyBuildTemplate: Template({
  id("MyBuildTemplate")
  name = "My build template"

  steps {
    powerShell {
        name = "Write First Message"
        id = "RUNNER_FirstMessage"
        scriptMode = script {
            content = """
                Write-Host "First Message"
            """.trimIndent()
        }
    }
  }
})

Then, you can define a build config extending this template:

object MyBuildConfig: BuildType({
  id("MyBuildConfig")
  name = "My build config"

  steps { // This would add a new step to the list, without wiping out the original step
    powerShell {
        name = "Write Last Message"
        id = "RUNNER_LastMessage"
        scriptMode = script {
            content = """
                Write-Host "Last Message"
            """.trimIndent()
        }
    }

    // afaik TeamCity would append the build config's steps to the template's steps but there is way to explicitly define the order of the steps:
    stepsOrder = arrayListOf("RUNNER_FirstMessage", "RUNNER_LastMessage")
  }
})

This way, you should also be able to inherit disableSettings from the template.

Tobias W
  • 260
  • 2
  • 8