The continuous integration is a frequent theme in the application development, expecially in the projects with many developers involved that work on differents components of the application.
Just because the developers works on different features, a process that integrate the new code frequently in project and verify that all the dependencies of that are working yet is recommended.
A practice to integrate daily the new code in the shared project repository avoid problems like integration hell, where a developer has troubles to integrate code of another developer, that worked isolated for a long period.
Again, a process that manage this integration allow us to introduce in this phase the automatic tests and discover eventually regressions in the code modified.
There are different products to manage the continuous integration process and one of those is Bamboo, a product owned by Atlassian and in this post I want to talk about the configuration of the continuous integration on a .NET project with a bunch of tests implemented with NUnit.
Before to proceed with a project configuration we need to take care about the executables that Bamboo will needs to execute the process.
In my case I need the MSBuild and NUnit executables and I can configure them in the server capabilities section of the Bamboo configuration:
In my case I use the MSBuild installed with Visual Studio, but you can download that from this url.
The NUnit console is the executable used for the tests execution and you can find it here.
When I need to configure a new project in Bamboo, I need to do a new plan.
A plan is composed by one or more stages; for example in my case I have a build stage, a test stage and a deploy stage.
In the stages I will create the jobs that will do some stuff.
In the plan configuration I need to take care about the referenced repository, that is the repository where Bamboo will load the source code:
In my case I have specified the url of a GitHub repository.
Another thing that I can do is define a trigger for the plan, that is an event after which the plan execution will be fired.
I define a branch that Bamboo will polling for new changes:
Every time a new commit will be pushed on the master branch, the plan will be executed.
Now I configure the Solution Build job in the Build stage; every job is composed by one or more tasks and in this case I have three tasks.
The first one is the Source Code Checkout, that is the phase where Bamboo get the source code from the repository and copy all the content in his working directory (locally on the server where is installed).
The second one is a Script configuration, in my case I need to restore some nuget packages before to build the project; I do that by writing a script that launch the nuget executable with the option restore:
You can find the nuget executable download here.
The last step is the MSBuild task and we use the executable configured above:
Another thing that we can do in the job configuration is define an artifact, thus the output of the job will be available for the next jobs:
In this way, we speedup the next job because it won’t need to checkout the repository again.
The test job is more simple, because it has the source code already available and it has only the test runner:
Again here we use the other executable configured above and we have only to specify the dll of the test project.
We don’t forget to configure the artifact for the job and use that produced in the previous job:
The last stage is the deploy.
To have a clean situation I do again a Source Code Checkout and than I execute a powershell script:
The script was explained in the previous post and deal with some stuff like build, apply a version to the assembly and copy the result in a shared directory.
That’s all, when you’ll run the plan, the result (if the project is ok :))) will looks like this: