Scenario
We have TeamCity 8.1.3 building every pull request. Build failures are reported in GitHub. This is great. However view errors are not picked up. This is bad. I could turn on MvcBuildViews across the board but I'd rather not as our solution is quite large and it roughly triples compile time.
What I'd like to do is enable MvcBuildViews only if a view has been changed in a commit in the PR. For example if someone changes a .cs file then compile as normal. If a .cshtml file is changed enable MvcBuildViews and compile.
What I've tried
My first attempt used VCS triggers. I set up two almost identical projects in TeamCity. The only difference was the VCS triggers. One build was designed to build code changes and the other view changes.
Code change trigger rules: -:\**.cshtml
and +:**.cs
View change trigger rules: +:**.cshtml
This didn't work as I'd hoped. Committing a .cs file and a .cshtml file on the same branch would trigger both builds.
My second attempt was using a PowerShell build step. I wondered if PowerShell could be used to read the teamcity.build.changedFiles.file agent build property, determine whether a cshtml file had been changed and if so set MvcBuildViews to true.
This failed because I couldn't figure out out to read the agent properties. I found this relevant SO question, but it didn't work.
My PS build step looks like this. I'm mostly clutching at straws here.
write-host "##teamcity[message text='Starting PhilTest build step']"
write-host "##teamcity[message text='Build number $env:build_number']" #Outputs build number
write-host "##teamcity[message text='Changed files $env:teamcity_build_changedFiles_file']" #Outputs nothing
foreach ($row in $env:teamcity_build_changedFiles_file)
{
write-host "##teamcity[message text='Changed files row $row']" #Outputs nothing
}
write-host "##teamcity[message text='Ending PhilTest build step']"
What next?
Has anyone done this before? Does anyone know how I can get one of my previous attempts to work or know of another way to do it?