I am following this Kotlin example (https://www.jetbrains.com/help/teamcity/kotlin-dsl.html#Editing+Kotlin+DSL) and trying to write a kotlin script for my CI.
This is my code snippet
steps {
script {
name = "Style check"
id("StyleCheck")
enabled = false
scriptContent = """
#!/bin/bash
make docker run="make ci lint"
""".trimIndent()
}
I get an Error for the id() call which says

id() call as given in the example?This error happens because the method id(String) is defined in an outer scope, and to prevent you from accidentally using the wrong method, Kotlin gives you a compiler error.
In your case you should make sure that there's no other id that you want to use. Perhaps you wanted to use the property named id instead of the method?
Note that neither of the options below might not have the same effect as you want. There might be a reason why the API is written like this to not allow you to call methods from outer receivers from inside inner scopes.
In order to use an explicit receiver, you can use this@methodName to call it. In this case, this@steps.
steps {
script {
name = "Style check"
[email protected]("StyleCheck")
enabled = false
scriptContent = """
#!/bin/bash
make docker run="make ci lint"
""".trimIndent()
}
}
To understand exactly what's going on, and another way of using an explicit receiver, you could also do something like the below, where you save the this scope in a variable and then call it inside the script scope.
steps {
val stepsThis = this
script {
name = "Style check"
stepsThis.id("StyleCheck")
enabled = false
scriptContent = """
#!/bin/bash
make docker run="make ci lint"
""".trimIndent()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With