We have a need that periodically, we will run a build configuration that among other things, recreates tokens/logins etc. We want to save these back to Team City as Environment variables. Builds that we subsequently do will want to look at this Environment Variable store and do a string replace within our configurations as required.
I've taken a look at :
##teamcity[setParameter name='env.TEST' value='test']
In order to persist a value back to a parameter you have to call the REST API.
I use a PowerShell script that acts as a wrapper around the
Invoke-RestMethod cmdlets in PowerShell 3+ that can be reused in a build step to achieve what you want.
Save the script to a PowerShell file and add it to your source control rest-api-wrapper.ps1
Create a PowerShell build step referencing the script and pass in the following arguments, tailored for your situation
More details can be found here - TeamCity Documentation
Hope this helps