Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a build template be based on another build template on TeamCity?

Tags:

teamcity

I am using TeamCity 9.0.2, and I would like to make a template implement another template, or make a build configuration implement more than one template.

Can this be achieved?

like image 370
Mat-Tap Avatar asked Sep 07 '16 21:09

Mat-Tap


2 Answers

This was not available when you asked the question but since Team City 10 you can now use Kotlin to configure your builds and thus your templates.

From this you can make Templates implement other Templates.

I myself have made Templates inherit from other templates to cut down on reconfiguration time and to not have to repeat myself so many times.

open class TheBaseTemplate(uuidIn: String, extIdIn: String, nameIn: String, additionalSettings: Template.() -> Unit) : Template({
    uuid = uuidIn
    extId = extIdIn
    name = nameIn
    /* all the other settings that are the same for the derived templates*/
    additionalSettings()
})

object DerivedTemplateA : TheBaseTemplate("myUuidA", "myExtIdA", "myNameA", {
    params {
        param("set this", "to this")
    }
})

object DerivedTemplateB : TheBaseTemplate("myUuidB", "myExtIdB", "myNameB", {
    params {
        param("set this", "to that")
    }
})

object Project : Project({
    uuid = "project uuid"
    extId = "project extid"
    name = "project name"

    buildType {
        template(DerivedTemplateA)
        /* the uuid, extId and name are set here */
    }

    buildType {
        template(DerivedTemplateB)
        /* the uuid, extId and name are set here */
    }

    template(DerivedTemplateA)
    template(DerivedTemplateB)
})

The above code might be very hard to understand. It will take some time to familiarise yourself with Kotlin, what it does, and how it interfaces with TeamCity. I should point out that some imports are missing.

Additionally, take the example with a pinch of salt. It is a quick example to demonstrate one way of templates implementing other templates. Do not take this example as the definitive way to do things.

like image 141
ZoSal Avatar answered Nov 06 '22 13:11

ZoSal


Unfortunately, this is currently not possible but already requested for a long time in TW-12153 (maybe you would like to vote for it).

To share several build steps among several build configurations or build configuration templates, I am using meta runners:

A Meta-Runner allows you to extract build steps, requirements and parameters from a build configuration and create a build runner out of them. This build runner can then be used as any other build runner in a build step of any other build configuration or template.

Although using meta runners works as a workaround for us, editing meta runners is not as convenient as editing a build configuration template (as it usually requires editing the meta runner definition XML file by hand).

Update 2021

As @zosal points out in his answer TeamCity meanwhile provides another way of sharing common build configuration data or logic by means of the Kotlin DSL. The Kotlin DSL is a very powerful tool but may not always fit in your specific scenario. I would recommend to at least give it a try or watch one of the introductory tutorial videos.

like image 44
CodeFox Avatar answered Nov 06 '22 11:11

CodeFox