CI/CD with gitlab-Jenkins-IIS
In this article I will describe my notes and hands on experienced to implement CI/CD for .Net Devs.
Before starting this article I assume that you know about the topics what is CI/CD and why it’s important. So i am going to the point.
- First install Jenkins in your windows server. Jenkins available for windows. I installed Jenkins in my Windows server 2016.
You can check here to download and install jenkins
2. So I think you installed and open in your browser. There are some steps to install jenkins like java need to be installed on your machine and some permission and open port.
3. Now we need to install build tools to build .net project. We will use msbuild tools. In this case In am using Visual studio build tools. You can download from https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
3. Now you need to install msbuild plugin for jenkins, that will actually bridge build tools with jenkins. To install plugin go to https://plugins.jenkins.io/msbuild/ this url and click on archive to get the plugin. So did you download .hpi file?
So how you will install plugin in jenkins?
Click Manage Jenkins-> Manage Plugins
Then Advanced->Upload Plugin and upload. It will upload and install pluginsto your jenkins.
4. After install plugin you should configure your msbuild with your build tools that you already installed now configure your msbuild like below.
You should go global tool configuration and put your msbuild path
5. Now also configure your git like below. You must install git client like git bash
from this below link https://git-scm.com/download/win
6. Now the time to add your project start building and deployment. Goto New Item->Freestyle Project(You can choose as per your need) Fill with a name and submit OK. You will get following UI.
7. You should fill with your repository URL and username password to pull
7. When it will pull and build
8. Configure your build variable.
Here is the MSBuild Parameter need to pass. Also you can see msbuild parameter arguments reference documents.
/p:DeployOnBuild=true
/p:DeployDefaultTarget=WebPublish
/p:WebPublishMethod=FileSystem
/p:SkipInvalidConfigurations=true /t:build
/p:Configuration=Release
/p:Platform=AnyCPU
/p:DeleteExistingFiles=True
/p:publishUrl=C:\inetpub\wwwroot\TestSite
9. Lastly how this will deploy to your IIS Server? Here we are using FTP to deploy to remote server. It also need jenkins PowerShell plugin to write this script.
Here you can use winscp to copy data from build server to target server through FTP. To do this you should install winscp n your build server.
Add-Type -Path “C:\Program Files (x86)\WinSCP\WinSCPnet.dll”
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionoptions.parseurl(“ftp://testuser:password@192.168.0.2/")$session = New-Object WinSCP.Session
$session.Open($sessionOptions)$session.PutFiles(“C:\inetpub\wwwroot\Site\TestSite\*”, “/amms-web/”).Check()
$session.Dispose()
Or we can use publish profile options to web deploy by following way. So you need to configure web deploy in your web server
- ‘& “$env:MSBUILD_PATH” src\CiCdExample\CiCdExample.csproj /p:DeployOnBuild=true /p:Configuration=Release /P:PublishProfile=FolderProfile.pubxml’.
That’s it. Now build and check.
Happy coding…