Jenkins Pipeline to deploy ASP .Net MVC Applications at SCM to local IIS Server
In this post, we will talk about deploying any ASP .Net MVC Applications kept on a Source Code Management (SCM) to the local IIS server using Jenkins Pipeline.
Pre-requisite
· Jenkins
· ASP .Net Application
· Source Code Management tool (I am using GitLab for this post)
· IIS Server
PS: I will not be talking about setting up the above pre-requisite in this post so request you to google for the setup if you need any help.
Jenkins configurations for MS-Build
- MS-Build Plugin Installed
2. Global Configurations for MS-Build
ASP .Net Application on GitLab
Here you can see there is a file named “Jenkinsfile” which contains the script for the pipeline (will be talking about it further in this post)
IIS Server Default Website
We will be using the “Default Web Site” on IIS to host our application.
Working on Jenkins Pipeline
1. Let us start by creating “New Item”
2. Create a Pipeline by giving a name and selecting “Pipeline”
3. Setting up the Pipeline to get the project from the SCM and running the script from the “Jenkinfile”
4. Now once “Save” the pipeline is ready to “Build Now”
The Build will complete and host the application on the IIS site name “Default Web Site”
Jenkinfile content
Detailing Jenkinfile
In this file, we have two steps named “stage”
- Source: This step gets the latest code from the SCM
- Build: This is the part which deals with the building and deployment of the code on the local IIS “Default Web Site” content folder “c:\inetpub\wwwroot”
More detail on the Build Stage
This below part of the code is running the MSBuild configured in Jenkins on the sln file
“\”${tool ‘MSBuild’}\” AspDotNetJenkins.sln
The below part is the paraments for the MS-Build that is to do the following:
/p:DeployOnBuild=true //Tell MS-Build to deploy on build
/p:DeployDefaultTarget=WebPublish //Use the WebPublish to Deploy
/p:WebPublishMethod=FileSystem //Use FileSystem for Publishing
/p:SkipInvalidConfigurations=true //Skip Invalid Configurations
/t:build //Do only the build
/p:Configuration=Release //Do the buld in release mode
/p:Platform=\”Any CPU\” //For any type of CPU
/p:DeleteExistingFiles=True //Empty the folder publishing the file
/p:publishUrl=c:\\inetpub\\wwwroot” //Publish at mentioned location
Check your deployed app
- Go to IIS and restart the website name “Default Web Site”
- Open your browser and go to http://localhost
Please reach out if you need any further assistance.