3

When storing configuration in VCS as Kotlin DSL, you're not supposed to hard code passwords and tokens, instead the "Tokens" should be used. The problem is, it's not documented properly.

Let's imagine I have a token credentialsJSON:78098495-5f8c-4935-82b5-03eafaf2adde containing the VCS key passphrase. How do I use it in the Kotlin DSL code?

I have tried the following:

params {
    password("GitHub-key-passphrase", "credentialsJSON:78098495-5f8c-4935-82b5-03eafaf2adde")
}

But, TeamCity will complain that parameter "GitHub-key-passphrase" is not specified. How to get the tokens to substitute?

alamar
  • 89

2 Answers2

5

My understanding is that it is a multi part affair.

  1. Add a Token in the TeamCity GUI (Versioned Settings > Tokens)
  2. Reference that Token in your Kotlin (which you have done above)
  3. In your build configuration, use the parameter that you have defined in your Kotlin.

So if you do something like:

params{
    add {
        param("system.myGithubPassword)", "credentialsJSON:78098495-5f8c-4935-82b5-03eafaf2adde")
    }
}

Then you should see (in the GUI) that your project now has a system parameter called myGithubPassword with a (hidden) value. You should also see (in the GUI) the projects/parameters for which that Token is being used - shown in the 'Tokens' page. You can then refer to %system.mygithubpassword% in any build locations that can handle TeamCity parameter substitution and TeamCity should handle parameter -> token -> password substitution.

From your description, you may be setting the token and parameter correctly, but then not using the parameter how you want/expect in the Build configuration.

That is how I think that it should work, but like you I've been finding the docs a bit tricky to follow on this...

https://www.jetbrains.com/help/teamcity/storing-project-settings-in-version-control.html#Managing+Tokens

GnomeDePlume
  • 151
  • 2
0

Try named constructor arguments

params {
    password(name = "GitHub-key-passphrase", value "credentialsJSON:78098495-5f8c-4935-82b5-03eafaf2adde")
}