ASP-Software-ASP ASP-Software-ASP

Continuous Delivery using ASP.NET MVC4 – Web API

This post will help you learn how to create continuous delivery using ASP.NET MVC4, which is a web API.

Software Needed

  • Jenkins
  • MSBuild
  • Web Deployment Tool 3.5
  • IISWebSiteCreation (Custom Application)
  • MSTests
  • GIT
  • Jenkins MSBuild Plugin
  • HTTP Requests Plugin

Both environments, deployment target server, and CI server must have Web Deployment Tool 3.5 installed to them.

Read More: API Testing Tutorial

Jenkins Set Up

Step 1

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.
API SOftware

Step 2

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.”
API-Software-Delivery
The following command line arguments need to be set exactly as they are outlined below:

  • /p:Configuration=Release
  • /p:DeployOnBuild=True
  • /p:DeployDefaultTarget=WebPublish
  • /p:WebPublishMethod=FileSystem
  • /p:DeleteExistingFiles=True
  • /p:publishUrl=”$WORKSPACEbuilds”
  • /p:publishUrl is the destination folder where the build will be located, at this point you can choose any location.

Step 3

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:

  • http://[IP/DOMAIN]:9000/create/website/{sitename}/{applicationPoolName=null}/{tcpPort=null}/{ipAddress=null}/{hostHeader=null}
  • 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

Step 4

Let’s call the service and start deploying our branches!
Configure the HTTP Request Plugin.
Add a new build step named “HTTP Request.”
API-SOFTware-Delivery3
URL: http://example.com:9000/create/website/$BRANCH_NAME
Method: GET
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 tha t will contain the built code, inside the main domain.

Step 5

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!
Command:

“C:Program Files (x86)IISMicrosoft Web Deploy V3msdeploy.exe” -allowUntrusted -verb:sync -source:contentPath=”%WORKSPACE%builds” -dest:contentPath=’C:inetpubwwwrootexample.com%BRANCH_NAME%
‘,computerName=’https://example.com:8172/msdeploy.axd?site=%BRANCH_NAME%’,userName=’USERNAME’,password=’PASSWORD’,authType=’basic’,includeAcls=’False’
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!

Download: IISWebCreatorService


Read More: Why Does Your Company Need to Outsource Software Development?

Gaston robledo

About the Author

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).
https://www.youtube.com/watch?v=5SQdCcbKYq4

  1. I believe this is among the most significant info for me.
    And i’m happy studying your article. But want to statement on
    few general things, The web site style is ideal, the articles is
    really excellent : D. Good process, cheers

  2. Hi Santex,
    I downloaded the compressed file IISWebCreatorService.gz, which contains a file called IISWebCreatorService (without extension).
    Can you help me with the steps to install this component please?

    In the tutorial you point out is a windows service, Do I must install it using InstallUtil?

    Thanks in advance.
    Regards

  3. Wow, incredible blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look
    of your site is fantastic, as well as the content!

  4. Pingback: mortgagecrow.com

Comments are closed.