我已经提取了Kotlin输出的Teamcity版本。我想创建一个基类,该基类定义了许多常用的步骤/设置,但允许单独的构建来扩展这些属性。
例如
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()
}
}
}
})
在此示例中,我想从基类继承步骤,但是添加与特定构建相关的其他步骤。另外,我想继承基本的disableSettings
(如果有)并禁用其他步骤。
这甚至可能吗?如果是这样,我将如何构建类以启用它?
答案 0 :(得分:0)
您可能已经找到了解决方案,但这是我将解决您的问题的方法。
就像GUI中一样,TeamCity支持构建模板。 在您的情况下,您将具有如下模板:
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()
}
}
}
})
然后,您可以定义扩展此模板的构建配置:
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")
}
})
这样,您还应该能够从模板继承disableSettings
。