Quick overview of how to set up Jenkins and Git for automated deployment of applications to Microsoft Internet Information Services (IIS) web server.
Install Jenkins and necessary components
- Install Jenkins
- The Jenkins box needs Visual Studio installed. (Whichever version you're using to develop the project.)
- Fire up Jenkins at http://localhost:8080/ and, in the menu (left margin) choose "Manage Jenkins".
- Select "Manage Plugins", select the "Available" tab, and install the MSBuild and Github plugins. (These will pull in dependencies.) After the install, Jenkins will need to restart.
Configure a Jenkins Job
- Only keep the last 5 builds, as each one contains a full copy of the Git repository
- This does nothing for actually integrating with Github, it simply makes the "Github" link on the far left for quick-access to the repo
- Github Repository URL
- BuildBot user credentials (Use a github user that has Owner access to the repo so it can auto-generate the webhooks on Github.)
- Set the branch to use whichever one you want the job to "listen" to.
- If you're behind a firewall, it's difficult to try to get the Github server-side hooks to post to the Jenkins server. Instead, we poll Github and build whenever we find new commits. Note, the syntax in the image means poll every 2 minutes.
- The MSBUILD step requires a user for the MSDEPLOY part of the build process.
- The user is defined and recorded in the MSDEPLOY "Publish Profile" described below, but the password needs to be provided at run-time, so we accomplish that by providing the password in the build configuration and mask it using a Password Masking jenkins plugin
- Fancy build number instead of boring incrementing integer
- Use Nuget.exe to restore the .NET Nuget/package dependencies required for the build
- Execute npm install to restore NodeJs dependencies
- Execute npm build script to build the javascript dependencies for the web application.
- It's very easy to use the "Publish Profiles" generated by Visual Studio. Normally we could just add them directly to source, but since this one has a special need for using SQL Authentication instead of MS-SQL Integrated Security, we need it to store raw credentials and therefore we can't keep it in git. SO! We handle it outside of version control and copy it in at build time.
- MSBUILD Jenkins plugin
- MSBuild.exe parameters for building/deploying the app:
/P:VisualStudioVersion=14.0
/P:Password=${PASSWORD_1} <-- References password from above
/P:AllowUntrustedCertificate=true
/P:DeployOnBuild=True
/P:PublishProfile=warehouse_test <-- This is the Publish Profile we copied in
/P:DeployIISAppPath="Your App Name" <-- This needs to match exactly the name on the target IIS deployment
/P:MsDeployServiceUrl=WEBSERVER <-- Target deployment server. Must have Web Deploy 3.5 installed
/P:Configuration=Release