Kotlin compile exception while generating code for custom buildstep

Hey guys,

I'm trying to create my own buildstep which should wrap certain param I always want to set. I followed https://stackoverflow.com/questions/51117570/how-to-create-custom-build-step-based-on-existing-one-in-teamcity-kotlin-dsl and came up with this:

object testConfig : BuildType({
name = "test"
steps {
postBadgeStatus {
name = "step1"
scriptContent = "%teamcity.build.checkoutDir%/SetAutoSDK.bat"
param("specific1", "test")
param("specfic2", "%test%")
}
}
})

fun BuildSteps.postBadgeStatus(init: ScriptBuildStep.() -> kotlin.Unit): ScriptBuildStep {
var result = ScriptBuildStep(init)
result.param("generic1", "%foobar%")
result.param("generic2", "%foobar%")
result.param("generic3", "%foobar%")
return result
}

but this leads to the following error/exception (241,11 is the steps opening bracket):

[ERROR] Compilation error settings.kts[241:11]: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: KtLambdaExpression
File being compiled: (241,11) in C:/Users/flori/AppData/Local/Temp/configs3538219171346858828dsl/settings.kts
The root cause java.lang.UnsupportedOperationException was thrown at: org.jetbrains.kotlin.codegen.context.CodegenContext.getOuterExpression(CodegenContext.java:222)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:336)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:294)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:410)
at org.jetbrains.kotlin.codegen.CallGenerator$DefaultCallGenerator.genValueAndPut(CallGenerator.kt:70)
at org.jetbrains.kotlin.codegen.CallBasedArgumentGenerator.generateExpression(CallBasedArgumentGenerator.kt:42)
at org.jetbrains.kotlin.codegen.ArgumentGenerator.generate(ArgumentGenerator.kt:70)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2709)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2680)
at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:42)
at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:14)
at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
at org.jetbrains.kotlin.codegen.StackValueWithLeaveTask.putSelector(StackValue.kt:67)
at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:125)
at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:118)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:438)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:419)

I couldn't find much valueable information about that tbh. In general I guess I'm on the right track with the Lambdas with Receivers like also described a bit here: https://blog.jetbrains.com/teamcity/2019/03/configuration-as-code-part-2-working-with-kotlin-scripts/ ?!

Any help on that would be appreciated! Thx in advance :)

-Flo

0
1 comment

Solved the problem with using a function instead of an object like:

fun testConfig : BuildType{
    val buildType = BuildType()
    buildType.name = "test"
    buildType.steps {
        postBadgeStatus {
            name = "step1"
            scriptContent = "%teamcity.build.checkoutDir%/SetAutoSDK.bat"
            param("specific1", "test")
            param("specfic2", "%test%")
        }
    }
    return buildType
 }

The rest of the code stays the same.

Cheers, Florian

0

Please sign in to leave a comment.