I love TeamCity and use it since a while to automate my build/release processes. As human we should never do the work a machine can do, we have certainly better and more interesting things to do.
The habit I saw in the different projects I worked for is to create new TeamCity builds for the branches you work on. It take quite some work to do, even with templates…
So I came with another way of doing it. It is leverage Git, PowerShell and the possibility to run TeamCity builds by “Accessing Server by HTTP”. Basically you just need to make a HTTP request to an Url like this:
http:``//testuser:email@example.com/httpAuth/action.html?add2Queue=bt10&system.name=<property name1>&system.value=<value1>&system.name=<property name2>&system.value=<value2>&env.name=<environment variable name1>&env.value=<environment variable value1>&env.name=<environment variable name2>&env.value=<environment variable value2>
We will also use the possibility to pass custom parameters (system properties and environment variables) through the HTTP request.
The parameter we want to pass is the Ref name of the Git VCS Root, so we start by setting it using a configuration parameter called BuildRefName, as this:
Then we need to add a configuration parameters for our TeamCity project with the name BuildRefName which we currently set to master, so that if the parameter is not defined it will default to this value:
Now that we have configured this you can already start a build from your browser by calling the URL!
Be sure to replace bt10 with your build id.
Nice ,but we want to get a step further and be able to start the build from PowerShell, which is quite easy!
To achieve this goal you add those two functions to your PowerShell profile:
Please adapt the tcBuild script by replacing the YourServerUrl, YourBuildId, Username, Password by your personal values.
The first function Get-Web is from this blog post: “Microcode: PowerShell Scripting Tricks: Scripting The Web (Part 1) (Get-Web)”.
The second, tcBuild, is quite easy and is the one you will use to start a build on the TeamCity server.
My workflow now is the following one:
- I commit on my local Git repository then
- when I want to run a build I push to the centralized Git origin repository in my branch then
- I start my build on the Git Branch from PowerShell by typing :
where Jobping-10-NewFeature is the name of my Git branch.
This is quite cool and give me also the possibility to run kind of personal builds!