In my previous article, “Getting Started with Jenkins and GitHub”, I showed you how to create your first Jenkins job and download the source of your project from GitHub. If your projects are stored in TFS, you can read how to setup your Jenkins job for TFS here: “Integrate Jenkins with Team Foundation Server“. The next logical step in your build will be to build your solution or projects. I will guide you how to do it via MSBuild as build engine and NuGet for downloading the necessary packages.
Install Jenkins Plugins
- Click Manage Jenkins link:
- Click Manage Plugins link:
- Click the Available tab and type the name of the desired plugin in the filter text box:
- Install the MSBuild Plug-in – This plugin makes it possible to build a Visual Studio project (.proj) and solution files (.sln).
Configure Build Step
- Open Manage Jenkins Page.
- Click Configure System link.
- Under the MSBuild section, click MSBuild Installations… button
- Enter Name- msbuild.exe
- Enter default path to msbuild.exe - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MsBuild
- Open the configure page of your Jenkins job
- Click Add build step button
- Select Build a Visual Studio project or solution using MSBuild
- For MSBuild Version, choose the configuration that you have created – msbuild.exe
- For MSBuild Build File – enter the path to the project/solution that needs to be built in the format - ${WORKSPACE}\PhantomTube\PhantomTube.sln (${WORKSPACE} is a Jenkins variable that contains the default workspace location)
- In Command Line Arguments – you can enter msbuild.exe arguments that you use when you build your project though command line. For example
/p:Configuration=Release
is going to build your project in Release mode. Or you can increase the logging verbosity, etc.
Configure NuGet Package Restoration
In order to restore NuGet packages, you have a couple of options. You can try some of the available plugins. However, my preferred approach is to use Windows batch command.
First, you need to download the NuGet.exe which you are going to use for the operation.
You need to paste a command like the following in the Command text box: “C:\J\Nuget\NuGet_2.81.exe restore “C:\J\jobs\PhantomTube\workspace\PhantomTube\PhantomTube.sln“”.
The step should be moved above the MSBuild step because in order for the build to be successful, you are going to need all package downloaded beforehand.
Now you are ready to test your setup. Open your job from the link listed on the main Jenkins page. Click the Build Now button.
If you open the console output, you can check the status of your build.
So Far in the Jenkins Series
- Integrate Jenkins with Team Foundation Server
- Integrate Jenkins and GitHub
- Configure Jenkins MSTest Tests Execution
- Delete TFS Workspace in Jenkins Job
- Output MSTest Tests Logs To Jenkins Console Log
- Integrate Jenkins with MSBuild and NuGet
- Create Jenkins Job for Creating NuGet Packages
- Visual Studio Test Agents Cleaning Scripts
- Jenkins Get Source Code By Specific TFS Changeset
If you enjoy my publications, feel free to <a href="http://automatetheplanet.com/newsletter/" target="_blank">SUBSCRIBE</a>
Also, hit these share buttons. Thank you!
The post - Integrate Jenkins with MSBuild and NuGet appeared first on Automate The Planet.
CTO and Co-founder of Automate The Planet Ltd, inventor of BELLATRIX Test Automation Framework, author of "Design Patterns for High-Quality Automated Tests: High-Quality Test Attributes and Best Practices" in C# and Java. Nowadays, he leads a team of passionate engineers helping companies succeed with their test automation. Additionally, he consults companies and leads automated testing trainings, writes books, and gives conference talks. You can find him on LinkedIn every day.