Jenkins – Create a Windows Visual Studio Project

This is a walk through of the configuration for the Jenkins Build for the Zebra Commerce Project.  As a prerequisite, the Jenkins server should already be installed and ready to build, refer to Jenkins – Windows Setup.

The Zebra Commerce build will perform the following tasks:

  • Monitor the Git repository for and changes (every 15 minutes)
  • Clone the Zebra Commerce Git Respository
  • Clean the Workspace to ensure a clean build
  • Run the Zebra Commerce Build script with the -NGIT flag (since Git is handled by the Jenkins Script)
  • Install the CoreFull version of ZebraCommerce to the local server
  • Create the Zebra Commerce Database for the Build
  • Import the Engineering Data Set

This configuration will create a full installation of the build that can then be used by the development team for testing.

Getting Started

The first step to creating a new build configuration is to create the project.  If this is the first project, simply select “create new jobs” to create the first project.  Otherwise, select “New Item”.
JenkinsZC_CreateNewJobs

Next you will enter the Project Name and type of a project.  In this case it will be a “FreeStyle project” which is the standard to start from.

JenkinsZC_1_CreateFreeStyleProject

A form is then displayed that allows you to configure all of the details of the project, starting with a description of the project. JenkinsZC_1a_ProjectNameAndDescription

Source Code Management

For this project, we are using Git for our SCM and will be monitoring the repository every 15 minutes for any changes.  If there is a change, we will automatically begin a new build.

In the Source Code Management section of the Project Configuration form, select Git for the type of SCM.  If Git is not an available option, the Git Plugin has not been installed, you will need to go back to the plug-in manager and add it.

When adding git you need to add the repository URL and the Credentials.

JenkinsZC_1b_SelectGitforSCMSource

By default Jenkins runs as the Local System Account so you can add the private key there, but I think a cleaner solution is to add the key directly through Jenkins.

JenkinsZC_1b_AddGitCredentialsNext we set up a few additional behaviors:

  • Set clone timeout to 60 minutes.  We do this because Zebra Commerce is a very large project and will time out at the 10 minute default.
  • Clean before checkout, so we always have a clean repository and don’t accidentally distribute objects from another build (we actually do this again later due to a bug in git).
  • Create a  new tag in the repository for each build.

JenkinsZC_1d_AddCustomGitBehaviours

Unfortunately the version of git that I am using has a problem with properly cleaning the repository, it does fails to delete a directory which has files that also need to be deleted, so we need to do an extra git clean.  To do, use the pre-scm-buildstep plugin to add an additional build step under the build section, “Add build step” and select “Execute Windows batch command”.  Add the command “git clean -fdx”.

JenkinsZC_1c_Git_Extra_Clean

By default, the project workspace is located in the Program Files, this is a bit hidden and also causes problems with long file names.  To move it change the directory in the Advanced Project Options.

JenkinsZC_1i_MoveBuildRepositoryWe then set the build triggers, in this case it will poll Git every 15 seconds to look for changes to the repository and will invoke a build if one occurs.
JenkinsZC_1e_SetBuildTriggerToPollSCM

The SCM configuration is complete, so now is a good time to run a test build and ensure that it is working thus far.  Select Build Now and the build will begin.JenkinsZC_1g_TestBuildSCMOnly

You can also view the console output of the build while it is progressing but either the menu for the striped building indicator or selecting console output on the menu for the build on the status page.JenkinsZC_1h_TestBuildSCMOnlyRunning

Run the Build

Now we setup the actual steps for the build.  In the case of ZebraCommerce this will be running a Perl script in the build directory.  This is done with the an “Execute Windows batch command” under the Build section.

One thing to be careful of is the path when running as Local System User, you may want to set it here as well, e.g. “set Path=%PATH%;c:\windows\system32;C:\Windows\Microsoft.NET\Framework\v3.5”

JenkinsZC_1j_RunBuildScript

Install the Build

Once the build is successful, we now automatically install the software in to a test environment.  This consists of:

  • Installing the Full version of the application
  • Restart the Data Import Services
  • Create the Database
  • Import the Test Data

This is accomplished by creating another “Execute Windows batch command” under the build section with all of the tasks.

JenkinsZC_1k_Install_Application

Archiving Artifacts

Finally, once the build is successfully completed and the application is installed, we need to archive an artifacts that we want to maintain long-term.  The way Jenkins works is that there is a work space that is used to create each build and there is also a separate area for those artifacts to keep longer term.  These artifacts are available for download from the Jenkins web interface.

In this case we will keep the installation files for the application which Zebra Commerce places in the bin directory, during the build.  This is created in the “Post-build Actions” section with the “Archive the artifacts option’.  In this case the bin directory does not yet exist, so we receive a warning, but once the build is completed it will work.

JenkinsZC_1l_ArchiveArtifacts

Leave a Reply

Your email address will not be published. Required fields are marked *