Score:0

Teamcity Versioned Settings: how to make use of Tokens

il flag

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?

Score:0
gs flag

Try named constructor arguments

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

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

il flag
The problem is, I don't have any locations that can handle parameter substitution, all of my locations are Kotlin code. The chief of which: when I declare param like this one (should I not use password?) then TeamCity complains that it is not defined, in spite it being declared with token value.
GnomeDePlume avatar
aq flag
Right, so your settings (configured / expressed in Kotlin) can set the parameter value and then your build configuration can use it. We use Kotlin to say that a parameter will have a value of <Token> and then at build time TC handles the substitution for us.
GnomeDePlume avatar
aq flag
What might be helpful (what I’ve been doing today) is using the GUI to set up the configuration that is desired, and then inspect the Kotlin DSL that is generated. I found that when I created a password entry TC would automatically create a new Token to handle it - and the resulting DSL contained the token name. I’m new to this too - using the GUI to generate some examples of Kotlin configuration is proving a helpful crutch right now.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.