Test server Combat server + Git + TeamCity how to organize work?

Share your experience as someone configures a test environment for web development.
We now have this:
The project is Backing WebAPI + Front SPA (MVC)
There is a fighting server.
There is a test server.
There is a fighting database, join in and battle and test server.
At Gita there are several branches. The branch master is a military branch and for any or change TeamCity build the project and publish it to production server.
In Gita there is also a branch of the developer, if you change where TeamCity builds the project and publishes it on the test server.
Everything would be fine but there's one catch. At the front in one of the files assigned IP API server. And for test and military build it is different port.

And every time you want to commit changes to the branch master has hands to change this IP, which is inconvenient.
So, how can I automate this process, or organize work, to get rid of manual correction of the file?
2 answers
June 10th 19 at 15:26
Well, you can file from the local settings to add in gitignore
That's not even thought about such a simple option :) - jayce48 commented on June 10th 19 at 15:29
June 10th 19 at 15:28
1. The build should parametrizatsiya that depends on the environment, in this case IP API
2. The transmission parameter may be performed in different ways: through the command line, configuration file, etc.
3. The build script needs to pass a parameter (to put the config) corresponding to the branch.

There are 100500 ways how to implement it, you should be seen as better. The main thing - take all environment settings from the app: addresses, ports, paths, etc.
I understand depending on the build configuration, TC may substitute certain variables in the setting file and publish the project with the modified settings?

Where can I read how to do it in the off documentation that I can not find about it? - jayce48 commented on June 10th 19 at 15:31
Done via Command Line in TeamCity - jayce48 commented on June 10th 19 at 15:34

Find more questions by tags TeamCityASP.NETDeploymentDevOpsContinuous integration