How can I parse a configuration parameter in kotlin dsl?

I would like to define a new environment variable in my kotlin dsl like this:

project {
params {
param("env.MY_NEW_ENV_VAR", compute_env_var_value())
}
[...]
}

I would like the compute_env_var_value() method to base on the value of configuration parameter %teamcity.build.branch%. It should parse that value, get the relevant information out of it, and generate a string that is then returned. Something like this, for example:

fun compute_env_var_value(): String {
val match = Regex("([A-Z]+)-(\\d+)").find("%teamcity.build.branch%")!!
val (project_name, issue_number) = match.destructured

return "$project_name-$issue_number"
}

What I noted is that this function does not evaluate the value of variable %teamcity.build.branch%. Instead, it really parses the string "%teamcity.build.branch%", instead of its actual value. Why is that?

Currently, the only solution I've found to this problem is to do the above parsing in a shell script where the %teamcity.build.branch% value is replaced with its actual value. Is there a way to do it in the kotlin dsl at all?

Thanks for your help

0
2 comments
Hello Laurent!
The function does not evaluate the value of the variable because such parameters are actually resolved when the build starts.
As a work around, you could have a separate build step that calculates the value and reports it to the build with a service message (such as a Kotlin Build Step with same code).
 
Thank you,
 
Guilherme
1

Please sign in to leave a comment.