Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing teamcity parameters in kotlin DSL

I am creating a kotlin DSL for a TeamCity project, and want to get the current branch name in the actual kotlin script.

If I run a script step, the current branch renders correctly

script {
    name="print branch"
    scriptContent = """echo "Branch is  %teamcity.build.branch%""""
}

From the actual settings.kts, I don't seem to have access to it

val currentBranch = DslContext.getParameter("teamcity.build.branch") //yields '<placeholder-1>'

How can I get this parameter in my Kotlin code?

like image 780
Jon Bates Avatar asked Oct 21 '25 18:10

Jon Bates


2 Answers

So it turns out it isn't possible - the DSL is merely used to express a config, and isn't invoked during the build process. In my case, I wanted to enable or disable some steps according to whether I was on main or a feature branch, so I created 2 BuildDefinition objects,, which subclassed the main build, passing in a bool of whether the branch was main. With that, I was able to enable or disable build steps and update the VCS triggers for each build

like image 57
Jon Bates Avatar answered Oct 25 '25 00:10

Jon Bates


What seems to work for me is

object : BuildType({
   val changeList = if ("%teamcity.build.branch%" == "master") "" else "-%teamcity.build.branch%"
   ...
   steps {
       maven {
           jvmArgs = "-Xmx1024m -Xss1g -Drevision=1.1.%build.counter% -Dchangelist=$changeList"
       }
   }
})

YMMV

like image 22
TimA Avatar answered Oct 24 '25 23:10

TimA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!