Follow the steps below to install, configure, run, and test Jenkins on a computer running Microsoft Windows.
Jenkins is a continuous integration server. Continuous integration is the practice of automatically re-building a software package whenever its source code is changed. It is typically used by groups of programmers working on a common project, where it is intended to identify errors introduced into the code as early as possible, so that they may be fixed quickly, thus minimizing their impact on other programmers on the team.
1. Follow the steps in a previous post to install Git and Xamarin Studio, create a test repository named “TestProject”, and publish that repository locally via HTTP. Make sure that the SCM Manager server program is currently running.
2. If you have not already done so, download and install a Java Development Kit (JDK). As of this writing, the latest version is available for download at the URL “http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html“. Make a note of the directory to which the JDK is installed, for example, “C:\Program Files\Java\jdk1.7.0_09”.
3. Download and install Jenkins. As of this writing, the latest version is available at the URL “https://jenkins-ci.org“. When running the installer, accept the defaults.
4. Open a web browser and navigate to the Jenkins page (probably at “http://localhost:8080“). If the install was successful, you should see the Jenkins homepage.
5. On the Jenkins main page, click the Manage Jenkins link. On the Manage Jenkins page, click the Manage Plugins link. On the Plugins page, click the Available tab.
6. Within the list of available plugins, locate the entries for “Git plugin” and “MSBuild Plugin”, activate the checkboxes on those entries, and click the “Install without restart” button at the bottom of the page. When the installation completes, click the “Go back to the top page” link to return to the main page.
7. Back on the Jenkins main page, click the Manage Jenkins link, then, on the page that appears, click the Configure System link.
8. On the system configuration page, scroll down to the heading “JDK” and click the “Add JDK” button. Enter the value “JDK” in the Name box. Deactivate the “Install immediately” checkbox, then enter the path of the JDK determined in a previous step.
9. Still on the system configuration page, scroll down to the heading “MSBuild” and click the “Add MSBuild” button. Enter the value “MSBuild” in the Name box, then enter the path of the file “msbuild.exe” in the Path to MSBuild box. For example, this path might be something like “C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe”. (A warning message may appear saying that the file does not exist, even if it really does. This is a known bug with Jenkins. Ignore it.)
10. At the bottom of the system configuration page, click the Save button.
11. Back on the Jenkins main page, click the “New Item” link. On the next page, enter the value “TestProject” in the “Item name” field, activate the “Freestyle project” radio button, and then click the OK button.
12. On the job configuration page that appears, scroll down to the “Source Code Management” heading, activate the “Git” radio button under this heading, and then enter the URL of the Git repository that was determined in a previous step. If the Git repository was set up as directed in the previous post linked above, this URL will be “http://localhost:8081/scm/git/TestProject“.
13. Still on the Jenkins job configuration page, scroll down to the “Build Triggers” section, activate the “Poll SCM” checkbox, and enter the value “H/5 * * * *” in the Schedule box to specify that the SCM should be polled for changes every five minutes.
14. Still on the Jenkins job configuration page, scroll down to the “Build” section and click the Add Build Step button. From the menu that appears, select the item “Build a Visual Studio project or solution using MSBuild”. Several new text boxes will appear. Select the value “MSBuild” in the MSBuild Version box. In the MSBuild Build File box, enter the value “TestProject.sln”.
15. Still on the Jenkins job configuration page, click the Save button to confirm the changes and return to the “TestProject” job’s page.
16. Back on the “TestProject” job page, click the “Build Now” link. Refresh the browser (perhaps by pressing F5) if necessary. The job should complete almost immediately, and a new entry should appear in the job’s build history, with a blue sphere next to it to indicate a successful build. A red sphere would indicate that there was an error with the build.
17. If necessary, create a new local clone of the “TestProject” Git repository by opening a command prompt, navigating to any convenient directory (perhaps “C:\src\” and running the command “git clone” with the URL of the desired repository. If the repository was created using the procedure described in a previous post, this command should be:
git clone http://localhost:8081/scm/git/TestProject
18. Start Xamarin Studio and open the “TestProject.sln” solution (perhaps at “C:\src\TestProject\TestProject.sln”) within it. Use Xamarin’s project explorer window to open the file “Program.cs”, then change the text of the message from “Hello World!” to “Hullo, Jenkins!”. Then save the solution by selecting the item “File – Save All” from the main menu.
19. Back at the command prompt, navigate to the top directory of the “TestProject” solution (perhaps at “C:\src\TestProject\”), then enter the following commands. These Git commands will commit the changes to the source code to the local Git repository, then push those changes from the local to the remote repository.
git commit -a -m "Changed message text." git push
20. Back in Jenkins, go to the “TestProject” job page, and wait up to five minutes for Jenkins to poll Git for the latest changes, refreshing the view as necessary. Verify that a new successful build is eventually added to the Build History list.
21. Click on the label of the new build (perhaps “#2”). On the page that appears, verify that the text “Changed message text” is present in the list of Changes.
22. Back in Xamarin Studio, introduce an intentional syntax error in the code by removing the semicolon from the end of the line containing the Console.WriteLine() call in Program.cs. Save the file.
23. Back at the command prompt, navigate to the top directory of the “TestProject” then enter the following commands to test how Jenkins handles build errors.
git commit -a -m "Intentional error to test Jenkins." git push
24. Back in Jenkins, return to the “TestProject” page , wait an additional five minutes or so, and verify that another new build appears in the Build History. This build should have a red sphere icon next to it, which indicates that there was an error during the build process. Click on the red sphere icon to see the “Console Output” of the build. The console output on a failed build will generally have information useful for debugging the error. In this case, it contains the error message “Program.cs(9,42): error CS1002: ; expected”
25. It would be wise to better secure the Jenkins installation at this time, but this is left as an exercise for the reader.