This post has been imported from my previous blog. I did my best to parse XML properly, but it might have some errors.
If you find one, send a Pull Request.
In the last entry I’ve shown how to create a PowerShell based git hook, passing following parameters to the hook for sake of validating it. The parameters were:
$local_sha - the signature of the local commit
$remote_ref - the remote branch name
This is more than enough to finalize our quest and test if the commit that is about to be pushed on develop was previously built in any other branch (in this case, a feature branch). To enable that we need a plan of attack. The check will consists of:
ensuring that $remote_ref name is equal to ‘develop’
querying TeamCity server for the status of $local_sha in any of the feature branches
The first point is a one liner. The secon d point is a bit more interesting. To do not write the whole integration with TeamCity in PowerShell, we can use TeamCitySharp library, which integration with PS is so well described in here. The easiest way to query for the specific commit build I’ve found so far, is to have a separate build for the features which enables to issue the following query against API (using buildLocator)
This list doesn’t provide all the needed information. So for each build in there, we need to query for more details. Once we got the build details, you can see that they include the SHA1 of the commit being build, which is exactly what we wanted.
This post ends this series of protecting the development branch. I hope it will help you to adjust and improve rules in your environment to decrease the number of failed builds on development and increase overall quality of your solution.