Kotlin DSL Examples in TeamCity
Tags: cicd, kotlin
Published: 2023-09-08 15:24:25

TeamCity offers the ability to define project settings and [configure CI/CD pipelines programmatically](https://www.jetbrains.com/teamcity/features/configuration-as-code/?_gl=1*lflsmt*_ga*MTk1MDA2NTY0LjE2OTM1NjkxMzA.*_ga_9J976DJZ68*MTY5NDE4NTQ3Ny4yNTYuMS4xNjk0MTg1NjUyLjYwLjAuMA..&_ga=2.264310726.8966633.1693814089-195006564.1693569130) with the help of the Kotlin DSL. 

To help you take advantage of the Kotlin DSL’s capabilities and simplify the build configuration process, we’ve created extensive Kotlin DSL documentation. It comes with examples that you can simply copy-paste directly into your code base.


![Kotlin DSL examples](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qcf771jhav4ybur05vr.png)

## How the Kotlin DSL documentation works
Every TeamCity server has its own Kotlin DSL documentation, which is automatically curated to match the TeamCity version and any plugins installed on the server. If you install a new plugin, the documentation compiles again, providing you with relevant examples.

You can also refer to the general Kotlin DSL documentation, which is available in [the TeamCity docs](https://www.jetbrains.com/help/teamcity/kotlin-dsl-documentation/index.html?_gl=1*1ngkdxf*_ga*MTk1MDA2NTY0LjE2OTM1NjkxMzA.*_ga_9J976DJZ68*MTY5NDE4NTQ3Ny4yNTYuMS4xNjk0MTg1ODA0LjYwLjAuMA..&_ga=2.269018168.8966633.1693814089-195006564.1693569130).

## Accessing the Kotlin DSL documentation from IntelliJ IDEA
The Kotlin DSL documentation is available right from IntelliJ IDEA (both Ultimate and Community editions). You can access it by going to **Maven Tool Window | Download Sources and Documentation**.


![Kotlin DSL in TeamCity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpcfjhtp3qva1p1ef1rf.png)

Another way to access the Kotlin DSL documentation directly from your IDE is to run the `mvn -U dependency:sources` command.

The documentation’s context and examples change when you click on an entity (for example, a build step or a trigger). The information is displayed either in a popup window or in the panel on the left, depending on the settings you’ve selected.

![Kotlin DSL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/88ukxsuaokeq3jphowng.png)

There are a few different ways to open the Kotlin DSL examples from your IDE:

1. Pressing `F1` on Mac or `Ctrl + Q` on Windows. Refer to [this section](https://www.jetbrains.com/help/idea/viewing-reference-information.html?keymap=windows&_gl=1*o4xs22*_ga*MTk1MDA2NTY0LjE2OTM1NjkxMzA.*_ga_9J976DJZ68*MTY5NDE4NTQ3Ny4yNTYuMS4xNjk0MTg1OTQ5LjYwLjAuMA..&_ga=2.8405116.8966633.1693814089-195006564.1693569130#keep-docs-in-tool-window) of the IntelliJ IDEA documentation for more details.
2. Clicking on the name of an entity (such as a build step or a command). The examples will open in the menu on the right-hand side of the window.
3. Simply hovering over an entity to access the in-line information window.

![Kotlin DSL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hta6fvgqh2p4t9wx2omv.png)

## How this feature is helpful
Using Kotlin DSL examples can save you time when configuring your pipelines as code. The examples also make it easier to discover all of the things you can do when configuring builds, in addition to helping you identify the scenarios that TeamCity can support.

Working with the Kotlin DSL examples can be a particularly great option when you are just getting started, as they provide a solid foundation on which to build your understanding of the Kotlin DSL.

TeamCity also provides you with an option to view your settings as code with the help of the **View as code** button, which is available on the build level. This displays your settings as code that you can copy and paste to your codebase.

If your project can’t be configured via the UI and you’d still like to experiment with the View as code feature, consider setting up a sandbox project on your TeamCity server. It will give you a chance to play around with different TeamCity features and see how they look in the Kotlin DSL.

## Further resources
If you’d like to learn more about using the Kotlin DSL for TeamCity, here are some additional resources that you might find useful:

- Video series “[Kotlin DSL: From Zero to Hero](https://youtu.be/Mxa-eHMe2w8)”
- Blog post “[Kotlin DSL for Beginners: Recommended Refactorings](https://blog.jetbrains.com/teamcity/2021/04/kotlin-dsl-for-beginners-recommended-refactorings/)”
- Blog post “[Creating TeamCity Project Templates with Kotlin DSL Context Parameters](https://blog.jetbrains.com/teamcity/2020/09/creating-teamcity-project-templates-with-kotlin-dsl-context-parameters/)”
- Blog post series “[Configuration as Code](https://blog.jetbrains.com/teamcity/2019/03/configuration-as-code-part-1-getting-started-with-kotlin-dsl/)”

## Over to you
Do you have any questions or comments about how we can improve the Kotlin DSL examples and documentation for TeamCity? We’d love to get your feedback! Feel free to share it in the comment section below. 

Happy building!