Loading...
Loading...
Marco Franssen

In part 1, 2, and 3, I showed you how to create an MSBuild script and run it from the command line. We covered cleaning output directories, downloading NuGet packages, compiling code, running MSpec tests, and generating a code coverage report. In this final part, we'll connect that build script to Jenkins.
First, we want Jenkins to pull the latest code from GitHub whenever someone pushes changes. For this setup, we'll install the GitHub plugin, the MSBuild plugin to run our build script, the HTML Publisher plugin to publish our coverage and MSpec reports, and the Jenkins Git plugin to configure repository access.
Once the plugins are installed, we can create a new project in Jenkins. In the "Source Code Management" section, we define our Git repository. In this example, I configured Jenkins to build only the develop branch.
We'll trigger the build as soon as changes are pushed to GitHub.
When the build is triggered, it should run our MSBuild script. Assuming our project targets .NET 4 and the script is in the root of our GitHub repository, we can use the following settings.
We'll choose the CI target, which runs several other targets in sequence. Add the following target to the MSBuild script. It first loads the NuGet packages, cleans the output folders, compiles the code, and then runs the code coverage and specification targets.
<Target Name="CI" DependsOnTargets="LoadNuGetPackages;Clean;Compile;CodeCoverage;Specs"></Target>Finally, we'll add a post-build action to publish the reports. In part 3, we configured the MSpec and coverage targets to write to the reports folder. We can display both reports in Jenkins by adding a post-build action with the HTML Publisher plugin.
The build project is now configured, but a few things still need to be in place. First, we need to generate an SSH key and add its public key as a deploy key to our GitHub repository. Jenkins will use it to pull the code into its workspace.
The key needs to be stored in C:\Windows\SysWOW64\config\systemprofile\.ssh (the Local System account's home directory in this setup). For details on generating an SSH key, see http://git-scm.com/book/en/Git-on-the-Server-Generating-Your-SSH-Public-Key. Don't forget to add the public key to your repository's deploy keys on GitHub.
Next, enable the service hook on GitHub. Enter the Jenkins hook URL and click "Test Hook". This should trigger a build on your Jenkins server.
I hope this series was helpful and gives you a starting point for extending your continuous build process with more automated tasks. Please share it with your friends, and let me know if you run into any issues.
Marco Franssen
Learn how to initialize, install, update, and publish Node.js packages with npm in this 2013 walkthrough, including development dependencies and private packages.
Marco Franssen
Build a simple Node.js web server with Express, use npm packages and nodemon during development, and serve an HTML page from a static public folder.
Marco Franssen
Extend a .NET MSBuild CI script with MSpec tests, OpenCover code coverage, and ReportGenerator reports that you can later publish through Jenkins.
Marco Franssen
Add Clean and LoadNuGetPackages targets to a .NET MSBuild script so your CI build clears previous output and restores missing NuGet packages before compiling.