Setting up Jenkins as a CI Server for .NET 3.5/4.0/4.5 projects using BitBucket
Recently, I joined a team at Tribal DDB Melbourne. I had convinced my team of developers to adopt an approach to streamline deployments of the various projects for our clients. I endeavored upon to look at Jenkins (previously named Hudson), a CI product derived from Java Sun to implement a continuous build approach for the developer teams. After a few days of google-ing up articles and blogs from places, I decided to come up with my own simple way of steps to get one up and running, along with the gotchas and traps. Considering not many blogs have documented gotchas with building projects targeting the .NET Framework 4.5, I have decided to include it here.
Step 1:
Download the latest version of Jenkins. Run the installer which automatically steps you through the wizard. The installer will automatically install the Windows Service with the user set as Local System User. Ensure that the service is running up. You can browse to Services and Settings and lookup Jenkins. It should say ‘Started’. (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service)
Step 2:
Restart your machine to ensure that the installation is performed completely.
Step 3:
Ensure that the Jenkins page can run. Fire up a browser and key in the following in the url, http:[your-machine-name]:8080. You should see landing page of your Jenkins Home page.
Step 4:
We need to install a few tools on our CI Server to support GIT since my team have already used BitBucket as their source control repository for their projects. This will require a few plugins such as Git Client and Server plugins, Jenkins GIT Plugin. This will be available on the Jenkins > Manage Plugins Page. The Jenkins GIT Plugin allows you to use MSBuild to build .NET Projects by specifying a location to the MSBuild.exe on the Jenkin’s configuration page. (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin) and whilst the Jenkins GIT Plugin allows communication between Jenkins and the BitBucket server. Next install the latest versions of GitBash and GitExtensions onto your server. After all this, you will get a ‘Git Bash’ icon on your screen.
Step 5:
Setting up communication between BitBucket and Jenkins is not enough by installing the plugins in step 4. We will need to setup authentication for Jenkins to allow to perform GIT commands to BitBucket server. Because Jenkins has no means of prompting the user to enter a password each time it intends to clone or pull from BitBucket, we will need to setup SSH Keys on our CI Server and BitBucket Read up here for more info on SSH and setting up SSH for Git. (https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git). In a nutshell, you will need to setup a private key on your CI server and a public key on your BitBucket account. Note your BitBucket account will be the admin account for Jenkins and thus it is important to remember the credentials to this account.
Step 6:
Add the SSH Keys to your CI server. Leave the passphrase blank for BitBucket to authenticate, otherwise you will be left with a hanging “Fetching upstream changes from origin” when attempting to run the build for the project. You can setup authentication later by managing users and this will be sufficient for security purpose to restrict people to particular project builds. This step got me confused as to why I left with a hanging “FUCFO” as above. Leaving the passphrase blank solved the problem for me as Jenkins will now be able to push and pull from Bitbucket.
Step 7:
Create a test project in Jenkins and setup the necessary details and configuration so that it points to your project nicely. A good test will be to check if Jenkins is able to clone your project successfully into its workspace. Once this is working successfully, you will be ready to start setting up the build on your .NET solution or .csproj.
Step 8:
Next it is time to setup your msbuild scripts. I found a good place to start is an article by Mustafa (http://www.infoq.com/articles/MSBuild-1). I never knew how easy it was to get started with MSBuild. Mustafa also explains well how to setup a proper Jenkins job, along with build triggering from a BitBucket push, etc.
Some of the recommended plugins:
Artifact Deployer Plugin
This artifact allows you to choose which directories you will like to deploy to the target destination (usually this is where you will have your websites located such as Inetpub)
https://wiki.jenkins-ci.org/display/JENKINS/ArtifactDeployer+Plugin
Hopefully if you have anything else to share, feel free to drop me a comment to see how you go with setting up CI with BitBucket.
Moredetail in setup MSBuild plugin: http://justinramel.com/2013/01/15/5-minute-setup/
This post is part of a series:
- Jenkins.NET
- Jenkins.NET Plugins
- Setup Jenkins.NET
- Setting up your first job
- Your first build
- Breaking the build
- Diagnosing and fixing a broken build
- Monitoring your build
- Running your tests
- Code Analysis
- Security
- Active Directory Security
For my final post on using Jenkins with .net, here’s how to set it all up in 5 minutes!
Recently, I joined a team at Tribal DDB Melbourne. I had convinced my team of developers to adopt an approach to streamline deployments of the various projects for our clients. I endeavored upon to look at Jenkins (previously named Hudson), a CI product derived from Java Sun to implement a continuous build approach for the developer teams. After a few days of google-ing up articles and blogs from places, I decided to come up with my own simple way of steps to get one up and running, along with the gotchas and traps. Considering not many blogs have documented gotchas with building projects targeting the .NET Framework 4.5, I have decided to include it here.
Step 1:
Download the latest version of Jenkins. Run the installer which automatically steps you through the wizard. The installer will automatically install the Windows Service with the user set as Local System User. Ensure that the service is running up. You can browse to Services and Settings and lookup Jenkins. It should say ‘Started’. (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service)
Download the latest version of Jenkins. Run the installer which automatically steps you through the wizard. The installer will automatically install the Windows Service with the user set as Local System User. Ensure that the service is running up. You can browse to Services and Settings and lookup Jenkins. It should say ‘Started’. (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service)
Step 2:
Restart your machine to ensure that the installation is performed completely.
Restart your machine to ensure that the installation is performed completely.
Step 3:
Ensure that the Jenkins page can run. Fire up a browser and key in the following in the url, http:[your-machine-name]:8080. You should see landing page of your Jenkins Home page.
Ensure that the Jenkins page can run. Fire up a browser and key in the following in the url, http:[your-machine-name]:8080. You should see landing page of your Jenkins Home page.
Step 4:
We need to install a few tools on our CI Server to support GIT since my team have already used BitBucket as their source control repository for their projects. This will require a few plugins such as Git Client and Server plugins, Jenkins GIT Plugin. This will be available on the Jenkins > Manage Plugins Page. The Jenkins GIT Plugin allows you to use MSBuild to build .NET Projects by specifying a location to the MSBuild.exe on the Jenkin’s configuration page. (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin) and whilst the Jenkins GIT Plugin allows communication between Jenkins and the BitBucket server. Next install the latest versions of GitBash and GitExtensions onto your server. After all this, you will get a ‘Git Bash’ icon on your screen.
We need to install a few tools on our CI Server to support GIT since my team have already used BitBucket as their source control repository for their projects. This will require a few plugins such as Git Client and Server plugins, Jenkins GIT Plugin. This will be available on the Jenkins > Manage Plugins Page. The Jenkins GIT Plugin allows you to use MSBuild to build .NET Projects by specifying a location to the MSBuild.exe on the Jenkin’s configuration page. (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin) and whilst the Jenkins GIT Plugin allows communication between Jenkins and the BitBucket server. Next install the latest versions of GitBash and GitExtensions onto your server. After all this, you will get a ‘Git Bash’ icon on your screen.
Step 5:
Setting up communication between BitBucket and Jenkins is not enough by installing the plugins in step 4. We will need to setup authentication for Jenkins to allow to perform GIT commands to BitBucket server. Because Jenkins has no means of prompting the user to enter a password each time it intends to clone or pull from BitBucket, we will need to setup SSH Keys on our CI Server and BitBucket Read up here for more info on SSH and setting up SSH for Git. (https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git). In a nutshell, you will need to setup a private key on your CI server and a public key on your BitBucket account. Note your BitBucket account will be the admin account for Jenkins and thus it is important to remember the credentials to this account.
Setting up communication between BitBucket and Jenkins is not enough by installing the plugins in step 4. We will need to setup authentication for Jenkins to allow to perform GIT commands to BitBucket server. Because Jenkins has no means of prompting the user to enter a password each time it intends to clone or pull from BitBucket, we will need to setup SSH Keys on our CI Server and BitBucket Read up here for more info on SSH and setting up SSH for Git. (https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git). In a nutshell, you will need to setup a private key on your CI server and a public key on your BitBucket account. Note your BitBucket account will be the admin account for Jenkins and thus it is important to remember the credentials to this account.
Step 6:
Add the SSH Keys to your CI server. Leave the passphrase blank for BitBucket to authenticate, otherwise you will be left with a hanging “Fetching upstream changes from origin” when attempting to run the build for the project. You can setup authentication later by managing users and this will be sufficient for security purpose to restrict people to particular project builds. This step got me confused as to why I left with a hanging “FUCFO” as above. Leaving the passphrase blank solved the problem for me as Jenkins will now be able to push and pull from Bitbucket.
Add the SSH Keys to your CI server. Leave the passphrase blank for BitBucket to authenticate, otherwise you will be left with a hanging “Fetching upstream changes from origin” when attempting to run the build for the project. You can setup authentication later by managing users and this will be sufficient for security purpose to restrict people to particular project builds. This step got me confused as to why I left with a hanging “FUCFO” as above. Leaving the passphrase blank solved the problem for me as Jenkins will now be able to push and pull from Bitbucket.
Step 7:
Create a test project in Jenkins and setup the necessary details and configuration so that it points to your project nicely. A good test will be to check if Jenkins is able to clone your project successfully into its workspace. Once this is working successfully, you will be ready to start setting up the build on your .NET solution or .csproj.
Create a test project in Jenkins and setup the necessary details and configuration so that it points to your project nicely. A good test will be to check if Jenkins is able to clone your project successfully into its workspace. Once this is working successfully, you will be ready to start setting up the build on your .NET solution or .csproj.
Step 8:
Next it is time to setup your msbuild scripts. I found a good place to start is an article by Mustafa (http://www.infoq.com/articles/MSBuild-1). I never knew how easy it was to get started with MSBuild. Mustafa also explains well how to setup a proper Jenkins job, along with build triggering from a BitBucket push, etc.
Next it is time to setup your msbuild scripts. I found a good place to start is an article by Mustafa (http://www.infoq.com/articles/MSBuild-1). I never knew how easy it was to get started with MSBuild. Mustafa also explains well how to setup a proper Jenkins job, along with build triggering from a BitBucket push, etc.
Some of the recommended plugins:
Artifact Deployer Plugin
This artifact allows you to choose which directories you will like to deploy to the target destination (usually this is where you will have your websites located such as Inetpub)
https://wiki.jenkins-ci.org/display/JENKINS/ArtifactDeployer+Plugin
This artifact allows you to choose which directories you will like to deploy to the target destination (usually this is where you will have your websites located such as Inetpub)
https://wiki.jenkins-ci.org/display/JENKINS/ArtifactDeployer+Plugin
Hopefully if you have anything else to share, feel free to drop me a comment to see how you go with setting up CI with BitBucket.
Moredetail in setup MSBuild plugin: http://justinramel.com/2013/01/15/5-minute-setup/
Moredetail in setup MSBuild plugin: http://justinramel.com/2013/01/15/5-minute-setup/
This post is part of a series:
- Jenkins.NET
- Jenkins.NET Plugins
- Setup Jenkins.NET
- Setting up your first job
- Your first build
- Breaking the build
- Diagnosing and fixing a broken build
- Monitoring your build
- Running your tests
- Code Analysis
- Security
- Active Directory Security
For my final post on using Jenkins with .net, here’s how to set it all up in 5 minutes!
Install
- Download the latest version of Jenkins from: http://mirrors.jenkins-ci.org/windows/latest
- Extract the setup files from the zip file.
- Run the Setup.exe.
- Accept all the defaults in the setup wizard.
- Jenkins will now be installed and the main Jenkins page will be open.
- Download the latest version of Jenkins from: http://mirrors.jenkins-ci.org/windows/latest
- Extract the setup files from the zip file.
- Run the Setup.exe.
- Accept all the defaults in the setup wizard.
- Jenkins will now be installed and the main Jenkins page will be open.
Add required .NET Plugins
- Download and install your required .NET framework from: http://www.microsoft.com/net/download
- Open the Manage Plugins page, from the Jenkins menu select Jenkins » Manage Jenkins » Manage Plugins.
- Click the “Available” tab.
- Tick the “MSBuild” plugin.
- Download and install your required .NET framework from: http://www.microsoft.com/net/download
- Open the Manage Plugins page, from the Jenkins menu select Jenkins » Manage Jenkins » Manage Plugins.
- Click the “Available” tab.
- Tick the “MSBuild” plugin.
Add optional .NET Plugins
- Tick the plugin for the source control management software your using.
- If you want to run unit tests as part of your build Tick your chosen testing plugin, this guide will use NUnit.
- Tick the “Active Directory Plugin” if you want to use Active Directory for Authentication.
- Tick the plugin for the source control management software your using.
- If you want to run unit tests as part of your build Tick your chosen testing plugin, this guide will use NUnit.
- Tick the “Active Directory Plugin” if you want to use Active Directory for Authentication.
Setup Jenkins
- Open the main setup page, from the Jenkins menu select Jenkins » Manage Jenkins » Configure System.
- Under the MSBuild section, click the “Add MSBuild” button.
- Set the name and path to MSBuild for example: Name: v3.5 Path to MSBuild: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
- Click the “Save” button.
- Open the main setup page, from the Jenkins menu select Jenkins » Manage Jenkins » Configure System.
- Under the MSBuild section, click the “Add MSBuild” button.
- Set the name and path to MSBuild for example: Name: v3.5 Path to MSBuild: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
- Click the “Save” button.
Setting up your first job
- From the Jenkins menu click Jenkins » New Job.
- Set Job name for example: Demo.
- Select the “Build a free-style software project” radio button.
- Then click the “OK” button.
- Jenkins will now create the Job workspace on disk and redirect you to the job configuration page.
- From the Jenkins menu click Jenkins » New Job.
- Set Job name for example: Demo.
- Select the “Build a free-style software project” radio button.
- Then click the “OK” button.
- Jenkins will now create the Job workspace on disk and redirect you to the job configuration page.
Source Control
This guide will use Subversion but there are many available.
- Under the Source Control Management section select the “Subversion” radio button.
- Set the Repository URL for example: https://jenkins-net-demo.googlecode.com/svn/trunk
This guide will use Subversion but there are many available.
- Under the Source Control Management section select the “Subversion” radio button.
- Set the Repository URL for example: https://jenkins-net-demo.googlecode.com/svn/trunk
Build Triggers
- Under the Build Triggers section, tick the Poll SCM checkbox.
- Enter “5 * * * *” in the Schedule text area, this translates to check for changes every 5 minutes.
- Under the Build Triggers section, tick the Poll SCM checkbox.
- Enter “5 * * * *” in the Schedule text area, this translates to check for changes every 5 minutes.
Build the Solution
- Under the Build section click the “Add build step” button and select “Build a Visual Studio project or solution using MSBuild”.
- Set “MsBuild Version” to V3.5 (The version we setup previously)
- Set “MsBuild Build File” to the name of the demo solution: Jenkins-net-demo.sln
- Click the “Save” button and you’ll be redirected to the Demo project page
- Click the “Build Now” link.
You’re done!
- Under the Build section click the “Add build step” button and select “Build a Visual Studio project or solution using MSBuild”.
- Set “MsBuild Version” to V3.5 (The version we setup previously)
- Set “MsBuild Build File” to the name of the demo solution: Jenkins-net-demo.sln
- Click the “Save” button and you’ll be redirected to the Demo project page
- Click the “Build Now” link.
You’re done!
No comments:
Post a Comment