And*_*kov 3 teamcity dsl kotlin
显然,TeamCity Kotlin DSL 中不支持元运行器生成。文件保留为纯 XML 格式。
如何使用可用的 DSL 功能来替换它?假设我想这样做:
steps {
step {
type = "mymetarunner" // compound meta-runner step
}
}
Run Code Online (Sandbox Code Playgroud)
如何mymetarunner使用 Kotlin 进行定义?
目前(TeamCity 2017.2),无法使用 Kotlin DSL 定义元运行器。
更新 如果不需要真正的元运行器,解决方案是Kotlin DSL中的一个小练习
为“metarunner”所需的设置定义一个容器类
class MyConfigClass {
var name = "Default Name"
var goals = "build"
var tasks = "build test"
var someUnusedProperty = 0
}
Run Code Online (Sandbox Code Playgroud)
为块定义扩展函数steps
fun BuildSteps.myMetaRunner(config: MyConfigClass.() -> Unit) {
val actualConfig = MyConfigClass() // new config instance
actualConfig.config() // apply closure to fill the config
// use the config to create actual steps
maven {
name = actualConfig.name
goals = actualConfig.goals
}
ant {
name = actualConfig.tasks
}
}
Run Code Online (Sandbox Code Playgroud)
随时随地使用扩展功能
object A_Build : BuildType({
uuid = ...
steps {
myMetaRunner {
name = "This name will be used by maven step"
goals = "build whatever_goal"
tasks = "more ant tasks"
}
}
})
Run Code Online (Sandbox Code Playgroud)
答对了!