Agile DevOps - Case of using Jenkins for multiple sites, implementations, and environments for .NET Cloud Apps (Part-2)

Posted by Ramesh Kumhar on Jul 3, 2018 7:24:00 AM
Find me on:

Jenkin Blog part 2

With multiple projects created on different versions of Visual Studio we forced the build to compile on a single target VS version using the /p and the /tv command line parameter.

Below is an example of the msbuild commands called in sequence to build all the project files with specific msbuild targets that work with publishing profiles to package the entire site in a ZIP file. 

msbuild.exe D:\Jenkins\Workspace\DEV\AdminPortal\AdminPortal.csproj /tv:12.0 /p:VisualStudioVersion=14.0 /p:Configuration=Release /t:Package

msbuild.exe D:\Jenkins\Workspace\DEV\CustomerPortal\CustomerPortal.csproj /tv:12.0 /p:VisualStudioVersion=14.0 /p:Configuration=Release /t:Package

msbuild.exe D:\Jenkins\Workspace\DEV\Webservice\Webservice.csproj /tv:12.0 /p:VisualStudioVersion=14.0 /p:Configuration=Release /t:Package

 

<MSBuild Targets="Package" Projects=...

 

We created two Jenkins projects. One to build and another to deploy the packages to various environments. The first project was configured to download all code from the git repo, restore the nuget packages, build all .csproj projects, one at a time, using the /t:Package option and specifying the configuration using the /p:Configuration parameter as given as shown in the above example.

Once all our sites were built successfully the second project was chained in Jenkins to invoke the deployment project to web deploy each sites to the DEV environment. We added multiple sites to be deployed sequentially. Below are few command lines for the deployment.

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='D:\Jenkins\Workspace\DEV\AdminPortal\bin\Package\AdminPortal.zip' -dest:auto,computerName='https://DEVSERVER:8172/msdeploy.axd', userName='DOMAIN\User',password='password',AuthType='Basic',includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"D:\Jenkins\Configs\DEVELOP\AdminPortal\Customer1.SetParameters.xml" -allowUntrusted -preSync:runCommand="C:\Windows\System32\inetsrv\appcmd stop site /site.name:Cust1.Adminportal.demo.com" -postSync:runCommand="C:\Windows\System32\inetsrv\appcmd start site / site.name:Cust1.Adminportal.demo.com"

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='D:\Jenkins\Workspace\DEV\CustomerPortal\bin\Package\ CustomerPortal.zip' -dest:auto,computerName='https://DEVSERVER:8172/msdeploy.axd', userName='DOMAIN\User',password='password',AuthType='Basic',includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"D:\Jenkins\Configs\DEVELOP\ CustomerPortal\Customer1.SetParameters.xml" -allowUntrusted -preSync:runCommand="C:\Windows\System32\inetsrv\appcmd stop site /site.name:Cust1.CustomerPortal.demo.com" -postSync:runCommand="C:\Windows\System32\inetsrv\appcmd start site / site.name:Cust1.CustomerPortal.demo.com"

...

Let’s take a look at the parameters in the web deploy command line from the Customer Portal

-source:package='D:\Jenkins\Workspace\DEV\CustomerPortal\bin\ Package\CustomerPortal.zip'

Specify the ZIP package created in the Build process

-dest:auto,computerName='https://DEVSERVER:8172/msdeploy.axd',userName='DOMAIN\User',password='password',AuthType='Basic',includeAcls="False"

Specify the Parameters of the destination IIS Server, including UserName and password to connect to the server.

-verb:sync

The sync operation synchronizes data between a source and a destination.

-setParamFile:"D:\Jenkins\Configs\DEVELOP\ CustomerPortal\Customer1.SetParameters.xml"

The SetParamters.xml file is very important for us as we use this to get the IIS Application path where the application needs to be deployed, along with the Web.config transformations that we need to do at deploy time. Refer to the section Folder structure of SetParameters.xml for more information.

-preSync:runCommand="C:\Windows\System32\inetsrv\appcmd stop site /site.name:Cust1.CustomerPortal.demo.com"

In case you want to run some command on the destination server before the web deploy starts to copy files; you can specify it using the –presync parameter, We are forcing the website to be stopped so that we don’t get any issues in the deploy process. We also faced some ACL issues, so better to stop the site and deploy

-postSync:runCommand="C:\Windows\System32\inetsrv\appcmd start site / site.name:Cust1.CustomerPortal.demo.com"

Need to start the site again, post the deployment process.

Explore more details in (Part 3)

 

Know more about our experience

 

 

Topics: Continuous Integration, TeamCity, MSBuild, DevOps, Jenkins, CI/CD, Continuous Delivery, Deployments, Bamboo