Kotlin DSL: How to verify changes being valid

Hi,

I am quite new to the Kotlin DSL - scouting it out for my team. I feel for me there is a lot of trial and error involved.
I have to push to main, then go to the versioned settings page and hope that there is no error coming up.

I was wondering, if there is some sort of Testing possible for this?
Like can I run the DSL as a dry run for example in GitHub as a Pull Request Check, so I can be sure the code in main is always working?

Unfortunately I could not find anything about that, so would be curious if there is a way to do so?

0
6 comments
Hi! 

There are two approaches (you can use either one or both):

Generate the XML configs locally using the `teamcity-configs:generate` Maven task:
https://www.jetbrains.com/help/teamcity/kotlin-dsl.html#Generating+XML+Configuration+Files+Locally

Have a local TeamCity server (the professional edition is free of charge) with a VCS Root pointing at the local repository in your dev machine. You can commit locally without pushing, and the local server will pick it up. Then you can review manually any possible issues with it. Any issue which might can be easily and quickly found. To find the duplicate IDs, the local server would need to have the same project structure as the production server.

Cheers,
Anatoly
0

Anatoly Cherenkov many thanks for your answer.

I found the feature of the generation parallel to waiting for an answer here. however I seem to get no issue, but when I then merge it into main and the teamcity server picks it up I do get the problem with the duplicated ids. Other times I do get an error when I use the generation goal via maven. unfortunately I haven't found a pattern yet.

Any idea why that is?

 

The local teamcity server is for me a good idea to work at the beginning, but I was planning to create a CI check and work with pull requests and I guess there this approach is not scalable unfortunately. But it will hopefullt help me a lot in the beginning where I currently try to find the right way to work with the id generation :) 

 

0

One example is as follows:I try to create a project with a CI build for pull requests.

object Teamcity : Project({
  name = "Teamcity"

val vcsRoot = GitVcsRoot {
  name = "orga/teamcity-settings"
  url = "git@github.com:/orga/teamcity-settings.git"
    branch = "main"
  branchSpec = "+:refs/heads/*"
  }

  vcsRoot(vcsRoot)

buildType(BuildType {
    vcs {
      root(vcsRoot)

      checkoutMode = CheckoutMode.ON_SERVER
      branchFilter = """
            +:*
            -:<default>
        """.trimIndent()
    }
    name = "Teamcity Build PR"

    steps {
      maven {
        pomLocation = ".teamcity"
        goals = "clean install teamcity-configs:generate"
      }
    }

    triggers {
      vcs {
        quietPeriodMode = DO_NOT_USE
        branchFilter = """
                +:*
                -:<default>
            """.trimIndent()
        perCheckinTriggering = true
        groupCheckinsByCommitter = true
        enableQueueOptimization = false
      }
  }
  })
})


when I run the generation the goal runs successfully.

but once I commit that to teamcity I get:

BuildType(uuid='', id='null', name='Teamcity Build PR'): mandatory 'id' property is not specified

BuildType(uuid='', id='null', name='Teamcity Build PR'): VCS root entry with empty id

VcsRoot(uuid='', id='null', name='<orga>/teamcity-settings', type='jetbrains.git'): mandatory 'id' property is not specified
0

Hi! I ran the teacmity-configs:generate task against this code in TeamCity 2023.05, and it gave me the same errors. You can specify the ID using the RelativeId() or AbsoluteId() methods. Example:

object Teamcity : Project({
  name = "Teamcity"

val vcsRoot = GitVcsRoot {
  name = "orga/teamcity-settings"
   id = RelativeId("OrgaTeamcitySettings")
  url = "git@github.com:/orga/teamcity-settings.git"
    branch = "main"
  branchSpec = "+:refs/heads/*"
  }

  vcsRoot(vcsRoot)

buildType(BuildType {
    vcs {
      root(vcsRoot)

      checkoutMode = CheckoutMode.ON_SERVER
      branchFilter = """
            +:*
            -:<default>
        """.trimIndent()
    }
    name = "Teamcity Build PR"
   id = AbsoluteId("MyProjectId_TeamcityBuildPr")

    steps {
      maven {
        pomLocation = ".teamcity"
        goals = "clean install teamcity-configs:generate"
      }
    }

    triggers {
      vcs {
        quietPeriodMode = DO_NOT_USE
        branchFilter = """
                +:*
                -:<default>
            """.trimIndent()
        perCheckinTriggering = true
        groupCheckinsByCommitter = true
        enableQueueOptimization = false
      }
  }
  })
})
0

Anatoly Cherenkov thanks for coming back to me. I appreciate that I can create IDs, but I would rather let the system generate the ids as I am using templates and superclasses a lot and that ID generation is blowing up the code.

 

In other classes the ID seems to be generated, why is this not the case here?

0
When you declare an object, e.g., `object Teamcity : Project({...})`, the object name, `Teamcity`, is used as the relative ID. On the other hand, if you initialize an instance of the GitVcsRoot class using the `val vcsRoot = GitVcsRoot {...}` expression, it doesn't have an object name, so you need to specify an ID. I hope this helps.
0

Please sign in to leave a comment.