After enabling Kotlin for project settings, editing of the project in the web UI may not be available right after the switch. TeamCity needs to detect its own commit in the repository, and only after that editing will be enabled. Usually it takes a minute or two.
Project Settings Structure
After the commit to the repository, you will get the the .teamcity settings directory with the following files:
To get familiar with Kotlin API, see the online documentation on your local server, accessible via the link on the Versioned Settings project tab in the UI or by running the
You can also use the Download settings in Kotlin format option from the project Actions menu. For instance, you can find a project that defines some settings that you want to use in your Kotlin DSL project and use this "download" action to see what the DSL generated by TeamCity looks like.
TeamCity allows editing of a project via the web interface, even though the project settings are stored in Kotlin DSL. For every change made in the project via the web interface, TeamCity will generate a patch in the Kotlin format, which will be checked in under the project patches directory with subdirectories for different TeamCity entities. For example, if you change a build configuration, TeamCity will submit the .teamcity/patches/buildTypes/<id>.kt script to the repository with necessary changes.
idis the absolute id of the project, the same id we'll see in browser address bar if we navigate to this project
parentIdis the absolute id of a parent project where this project is attached
uuidis some unique sequence of characters.
uuidis something which associates a project, build configuration or VCS root with its data. If the
uuidis changed, then the data is lost. The only way to restore the data is to revert the
uuidto the original value. On the other hand, the
idof an entity can be changed freely, if the
uuidremains the same. This is the main difference of the non-portable DSL format from portable. The portable format does not require specifying the
uuid, but if it happened so that a build configuration lost its history, one has to reattach it again via the web interface.
In case of non-portable DSL, patches are stored under the project patches directory of .teamcity:
To use an external library in your Kotlin DSL code, add a dependency on this library to the .teamcity/pom.xml file in the settings repository and commit this change so that TeamCity detects it. Then, before starting the generation process, the TeamCity server will fetch the necessary dependencies from the Maven repository, compile code with them, and then start the settings generator.
FAQ and Common Problems
Add .teamcity as a
New Module to a
Question: How to add the .teamcity settings directory as a new module to an existing project in IntelliJ IDEA?
- Fix the URL in the Kotlin DSL in the version control and push the fix.
- Disable versioned settings to enable the UI.
- Fix the URL in the VCS root in the UI.
- Enable versioned settings with same VCS root and the Kotlin format again, TeamCity will detect that the repository contains the .teamcity directory and ask you if you want to import settings.
- Choose to import settings.
Read Files in Kotlin DSL
Problem: I want to generate a TeamCity build configuration based on the data in some file residing in the VCS inside the .teamcity directory