JetBrains / teamcity-pipelines-dsl

Experimental Kotlin DSL library for TeamCity pipelines
Apache License 2.0
40 stars 20 forks source link

How to configure Android Studio to use .teamcity code files in project? #8

Open jisasava opened 4 years ago

jisasava commented 4 years ago

I am trying to setup a TeamCity project configuration using Kotlin DSL. I've created a sample project in TeamCity pointing to just an empty Android Studio project with empty Activity which I 've published in the github. I've enabled Kotlin DSL configuration on the TeamCity for that project.

After that TeamCity has commited a .teamcity folder to my Android Studio project. However, when I am inspecting the code in settings.kts the IDE is not giving me any hints and I cannot use the autocompletion for the Kotlin DSL configuration code. For example I cannot navigate to implementation of function triggers, cannot use autocompletion etc.

I was trying to follow https://blog.jetbrains.com/teamcity/2019/03/configuration-as-code-part-1-getting-started-with-kotlin-dsl/#commento-login-box-container but unfortunately I cannot right-click on the pom.xml file and don't see any option to Add as Maven. In addition I cannot see any External Libraries added to my project related to TeamCity DSL

I am using Android Studio 4.0

Is it possible to use such configuration in my case? If so, can you please help me how I should properly setup it in Android Studio to have such benefits in Android Studio? Android Studio project uses Gradle by default

timdaman commented 4 years ago

I am not familiar with what you are doing specifically but I manage a non-trivial amount of TeamCity Kotlin config.

The lack of doc is frustrating and make using the DSL much harder than it needs to be. Here a couple hints that might help.

  1. The intelliJ IDE, after you load the pom.xml, provides hinting and have very good lint checking to help catch errors before committing. Also, buried in the Maven menus is a option to "Generate" a configuration which essentially does the same thing that server does and catches most errors the server would throw.
  2. I have a test teamcity project with no restrictions. In this project I can use the GUI to make changes and then examine the results. There are two ways I use this. The first is simply to make and save the change and the export the whole project as Kotlin (look for this under the actions menu of the project, it is not shown in the buildTypes action menu). The other way is to look for the "DSL" button in the GUI. There are many settings that, before they are saved, can show you the resulting Kotlin. This allows me to get a quick peek on what the setting should look like and even allows me to make a copy so I can paste in the code in the .teamcity directory.

Hope that helps.

jisasava commented 4 years ago

@timdaman I also agree with your opinion of struggling with simple task as this is not relevant to other CI clients (such as Github CI, Jenkins or Gitlab CI).

  1. Can you please elaborate more on that? If it is not possible to use such setup for my project in Android Studio then maybe it is possible in IntelliJ Idea. Unfortunately I was trying without luck in IntealliJ Idea Community edition. After right-clicking on the .teamcity folder and choosing "add as Maven" I encounter another error, IDE cannot resolve the jetbrains import packages and the Libraries are also not present. You can find the project here: https://github.com/jisasava/KotlinTeamcityDSL. Is it possible to configure this project to be working as expected in IntelliJ?

  2. This approach is something which does actually makes the main purpose of configuration as code not useful. This "configuration as code" should be the main trait of switching from TeamCity control panel in web (GUI) to the code. As you describe I would still need to work with TeamCity UI mainly, and just copy pasting the configuration as a plain text (code). Thank you for your engagement to my question I really appreciate it.

timdaman commented 4 years ago

I am short on time so I am not going to write a detailed answer right now.

You issue with adding the Maven project is probably related to the teamcity-server config in the pom.xml.

To initially create a project it is best to download a empty one from the TeamCity server in question. There are a couple reasons.

  1. There are several versions of the DSL/API. When you download the the settings as generated on the server it will automatically set this to a version supported by the server.

  2. The TeamCity server runs a secret Maven server. In the pom.xml the server generates it sets paths to download the libraries from itself. I noticed when looking at your linked pom.xml it is referencing http://localhost:8111/app/dsl-plugins-repository. If you did use the server to generate this pom.xml ensure that the server is running and reachable at the address configured in the pom.xml when you are importing/adding it.

jisasava commented 4 years ago

@timdaman Hello, thanks again for your answer. I've tried to firstly run the server as you suggested (I am using docker image and configuration exact as described here: https://nad.dev/posts/2020/01/06/teamcity-server-agent-docker.html

I've just tried to open an alone .teamcity folder in the IntelliJ Idea Community Edition. Unfortunately still I cannot setup it properly, I am getting unresolved errors:

Screenshot 2020-07-15 at 22 24 39

Maybe you can describe me the exact steps how can I run the code in IntelliJ?

jisasava commented 4 years ago

@timdaman I've also created some video which shows (perhaps in more details) the problem that I am encountering: https://www.youtube.com/watch?v=t4AboFhtb60&t=3s