3

I have a settings file settings.json, which holds api authorization key that is required for the test project to run and successfully pass all the test cases.

I have included settings.json in the .gitignore so I do not accidentally publish the api authorization key to github.

The team city build is triggered when I do a check in to github repository. The test cases fail since settings.json does not exist in the repository.

When I run the project locally, I always copy the settings.json file to the outputdirectory and the tests pass.

How do I pass the settings.json in team city to build the project successfully, without checking in settings.json to github.

Testing Framework: MSTest

vyshak s
  • 33
  • 3

1 Answers1

1

Create a powershell script step in teamcity and specify the script content in the step definition. The script will create the json file. Make sure the step is before your unit test step. You can create a build configuration variable to store the apikey, and use teamcity variable replacement in the script body.

This assumes you're the only one that will be accessing the teamcity server.

Andy
  • 8,432
  • 6
  • 38
  • 76
  • 1
    Thank you @Andy. Your approach worked. This is the script that I wrote @{ApiAuthKey="%ApiAuthKey%"} | ConvertTo-Json -Compress | Out-File settings.json. Additionally, I had to change the working directory in the powershell build step to **TestProject\bin\Release\netcoreapp2.1**, since I always output the **settings.json** to output directory and it is read from there when run locally. – vyshak s Nov 08 '18 at 05:09