Sunday, January 15, 2012

Continuous Integration( Part three) Things That can be done from the Build Server Side


Note : If you are interested in installing jenking build server for .Net applications I found an interesting post which has a good step by step explanation. 
Before going through this blog post I would recommend you to go through following blog post which gives you knowledge which is useful to understand the things mention in this post.
As I mentioned in above CI-Part Two we can create a IIS deploy-able packages with different configurations on the built server machine.

 Requirement : 
 "Automate the deployment process on IIS location for every successful  build.Moreover I need to automate multiple deployment with different configurations."

If I breakdown above requirement further, it is obvious that my first task is to create multiple packages with different configurations if and only if the build process is successful. In this case I may need some support of build server side to trigger me after a successful build. Once build server trigger me I have to think of creating packages with different configs. First question arise is as follows.

Me : Hey Jenkings, Do you have a plugin which you can trigger me after a successful build ? 
Jenking : Yes. I do have many which you can get your job done.
Me : Thank god. Then I will be surviving..... :) 

There is a good plugin to get this job done which is called Jenkins post built task plugin. By using above file I can execute any command line operation by checking the status of the build server build report. So what can I do is searching through the build report and find the build status. And then if it successful then execute a batch file or simple command line operation for the deployment. By ticking on the post built task you can get the following post build task. (In this example it runs the script if the build is failed)












So now we have a way to trigger a batch command if the build is successful.Then the next task is to find a way to do deployment automation.First I need to think about a way of creating packages with different configurations.I found following possible approaches of doing the packaging.
  • Assign Multiple jobs to jenkins server for different configurations :
In project configuration section you may find the build task. Here you can explicitly tell jenkins build server the configuration you want to build and package.(Simple it accepts MSBuild external parameters)


In this comamnd line argument section you can pass /t:package /p:buildsever and then it package web project which has the build server configuration. Similarly what you can do is assign new job to the jenkings server and in that job in the build section pass other configuration which you want to create the package.(eg: Live Server Configurations)
  • Build the package with multiple configuration by using a single Jenkings job:
Only change is in the command line argument section you can add two configuration which separated as follows.
              /t:package /p:buildsever;liveServer
But in order to get this job done you need some changes in the sln/csproj file which you are referring in the build server. This post will helps you to get this project file configuration done. 

     
At this point we are almost done with the packaging process.Next remaining thing to be done is deployment process of multiple package.Here I would suggest following approaches to to do it.

  • Use XCOPY command to copy the newly build package in to IIS location :
In this approach what you need to do is execute XCOPY command in Script section in post build plugin section.
 cd to project location in build server          
 XCOPY Views \\ES-WEBSRV01\Library\Views /e /y /i
 XCOPY packages.config \\ES-WEBSRV01\Library /y  


Similarly you need to copy all required folders in to IIS location.
\\ES-WEBSRV01\Library is the place where we deploy our IIS application.If your IIS location is on a another machine rather than the build server machine you need to share the location with the build server machine as above.But here we have a tricky problem. As i mentioned in my previous blog post there is a issue with the web.config file.So what we need to do is go to the project\obj\release\TransformWebConfig\transformed in the build server and get the transformed web.config file and then XCOPY it in to IIS location.(here release means you configuration)

Note : You need to do this for all packages built by the build server
  • Deploy using msdeploy command line tool ;
You can find your installed msdeply.exe in C:\Program Files\IIS\Microsoft Web Deploy

Once build server created the web package you can see a windows batch file named projectName.deploy  in Project\obj\release\Package. In the post built plugin script section what you need to do is run this batch file and it does the deployment.For that you need to go to the file where you can find msdeploy.exe and then run that batch file as follows.
C:\Program Files\IIS\Microsoft Web                               Deploy>H:project\obj\release\Package\MVC-Client.deploy.cmd /T 
It will deploy you web application in to the IIS location with the correct configurations which you want to deploy.

Note : You need to do this for all packages built by the build server


1 comment:

  1. You need to configure deployment location from VS2010.
    Package Publish setting > IIS location

    ReplyDelete