By Gastón Robledo, Architect at Santex
This post will help you learn how to create continuous delivery using ASP.NET MVC4, which is a web API.
- Web Deployment Tool 3.5
- IISWebSiteCreation (Custom Application)
- Jenkins MSBuild Plugin
- HTTP Requests Plugin
Both environments, deployment target server, and CI server must have Web Deployment Tool 3.5 installed to them.
Jenkins Set Up
Create a Jenkins job that will pull the code from a specific branch of code. To do this, you must set a String parameter to receive the branch name to build.
Once Jenkins clones or pulls the code from that branch, we need to call MSBuild to actually build the code. In order to do this, Jenkins MSBuild Plugin must be installed and configured as a build step.
Add a new build step named “Build a Visual Studio project or solution using MSBuild.”
The following command line arguments need to be set exactly as they are outlined below:
/p:publishUrl is the destination folder where the build will be located, at this point you can choose any location.
IISWebSiteCreation (.NET Framework 4.5 – Custom Component)
Download, build, and install the attached component into the deployment server.
IISWebSiteCreation is a windows service that I wrote in C# that allows you to create websites on IIS. This Windows service exposes a url so we can call it from Jenkins to create a website.
How to use the component:
sitename = The name of the branch in this case.
Parameters that can be set as default in the app.config file:
applicationPoolName: AppPoolName of IIS
tcpPort: Port where the website is listening requests.
ipAddress: If you have more than one IP to listen on IIS you can put here what you want. Default = ‘*’
hostHeader: Here you can put the header of the website like my_branch.example.com
Let’s call the service and start deploying our branches!
Configure the HTTP Request Plugin.
Add a new build step named “HTTP Request.”
Where $BRANCH_NAME is the branch code that we indicate to Jenkins to pull the code from, so that the service will create a site named http://branch_name.example.com on IIS pointing to a specific folder that will contain the built code, inside the main domain.
Now, let’s call the Web Deploy command.
Create a build step name “Execute Command.”
Hint: It is best not to reveal the password or anything on the Jenkins job configuration. To avoid doing this, create a cmd file and put it on the Jenkins server. It’s up to you!
“C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe” -allowUntrusted -verb:sync -source:contentPath=”%WORKSPACE%\builds” -dest:contentPath=’C:\inetpub\wwwroot\example.com\%BRANCH_NAME%
Once it finishes, you can go to http://[branch_name].example.com in the deployment target server and you will see your code deployed!
I hope you enjoy it!
Gaston Robledo is a versatile System Architect that specializes in enterprise software development and has more than 10 years of experience in the IT industry. Gastón started his career exclusively as .NET developer and over the years expanded to include a wide array of technologies (.NET, PHP, Java and Python). He adapts quickly and excels in almost any programming language. He enjoys collaborating with innovative teams and laterally thinking problems. Gastón always challenging himself to come up with an out-of-the-box solutions.