{"id":477,"date":"2018-08-27T11:36:00","date_gmt":"2018-08-27T06:06:00","guid":{"rendered":"http:\/\/nxglabs.in\/etech\/?p=477"},"modified":"2018-08-27T11:36:00","modified_gmt":"2018-08-27T06:06:00","slug":"continuous-integration-deployment-tools-net-application-using-jenkins-file","status":"publish","type":"post","link":"https:\/\/nxglabs.in\/etech\/continuous-integration-deployment-tools-net-application-using-jenkins-file\/","title":{"rendered":"Continuous Integration and Deployment Tools for .Net Application Using Jenkins File"},"content":{"rendered":"<p>This post describes how to\u00a0dockerise the dotnet application using continuous\u00a0integration and continuous deployment tool Jenkins. However, before trying this we need to set up Jenkins\u00a0pipeline. Through that, we can deploy the .net application automatically. Depending on this, we need some docker images for building the dotnet project.<\/p>\n<p>To get the docker images we will be using docker registry with just a few configurations.<\/p>\n<p><strong>Basic Configuration to Auto-Deploy .Net application<\/strong><\/p>\n<ol>\n<li>We need to install Docker container with docker registry.<\/li>\n<li>We need a &#8216;msbuild&#8217; folder. As per the project requirement, we must have msbuild.exe\u00a0file existing on the server.<\/li>\n<\/ol>\n<p><strong>Pre-requisites:<\/strong><\/p>\n<p>1. Jenkinsfile\u00a0in the source code.<\/p>\n<p>2. Dockerfile in the source code.<\/p>\n<p>3. We need &#8216;msbuild&#8217; folder to build the dotnet application.<\/p>\n<p><strong>Steps to auto-deploy dot net application using Jenkins server &#8211;<\/strong><\/p>\n<ol>\n<li>Setup Jenkins pipeline settings.<\/li>\n<li>Commit the code on the Git\/Bitbucket server.<\/li>\n<li>Code must include DockerFile and Jenkinsfile.<\/li>\n<\/ol>\n<p><strong>Explanation of Jenkinsfile and Dockerfile\u00a0commands:<\/strong><\/p>\n<p><strong>1.Dockerfile explanation with commands-<\/strong><\/p>\n<p>Step1: To build the dotnet application we need docker image of aspnet. We have to pull the image of aspnet from docker registry.<\/p>\n<p>command: <em>FROM <\/em>microsoft<em>\/<\/em>aspnet<\/p>\n<p><strong>Explanation:<\/strong> # The `FROM` instruction specifies the base image. You can actually do this by just extending the `microsoft\/aspnet` image.<\/p>\n<p>Step2: We have to write the code to copy the site you published earlier into the container.<\/p>\n<p>Here &#8220;yourprojectpublish&#8221; is the folder name to be copied in inetpub directory<\/p>\n<p><strong>command :<em>\u00a0<\/em><\/strong><em>COPY .\/bin\/publish\/_PublishedWebsites\/yourprojectpublish \/<\/em>inetpub<em>\/<\/em>wwwroot<\/p>\n<p><strong>2.Jenkinsfile explanation with commands-<\/strong><\/p>\n<p>step1: First we have to build the project using MSBuild. To build the project we need .sln\u00a0file. Here yourproject.sln is the name of the solution file. We have to give configuration as debug\/release mode. We have to assign the output directory path.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<p><em>stage (&#8216;Build&#8217;)<\/em><br \/>\n<em>{<\/em><br \/>\n<em>steps {<\/em><br \/>\n<em>bat &#8220;msbuild.exe yourproject.sln \/p:Configuration=Release \/property:OutDir=bin\/publish \/p:Platform=\\&#8221;Any CPU\\&#8221; \/p:ProductVersion=1.0.0.${env.BUILD_NUMBER}&#8221;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p>step2: Once we build the project using solution file, we have to build docker image for publishing the project. Here, &#8220;yourproject&#8221; is the name of folder where we have to publish and &#8220;nxglabs&#8221; is the docker registery username.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><em>stage (&#8216;BuildDockerImage&#8217;)<\/em><br \/>\n<em>{<\/em><br \/>\n<em>steps {<\/em><br \/>\n<em>powershell &#8216;docker build -t nxglabs\/yourproject .&#8217;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p>step3: Here we will push the publish folder on docker registry by providing credentials of docker registry id. Credentials can be created form the &#8220;manage credentials&#8221; section of Jenkins.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><em>stage(&#8216;PushDockerImage&#8217;)<\/em><br \/>\n<em>{<\/em><br \/>\n<em>steps {<\/em><br \/>\n<em>withDockerRegistry([ credentialsId: &#8220;b1fee946-b93a-46e0-ac78-abb78aea7cc2&#8221;, url: &#8220;&#8221; ]) {<\/em><br \/>\n<em>powershell &#8216;docker push nxglabs\/yourproject&#8217;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p>steps4:We will publish the dockerimage by giving the port number. Here yourprojectcontainer is the the container used which has to be published automatically.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><em>stage(&#8216;RunContainer&#8217;)<\/em><br \/>\n<em>{<\/em><br \/>\n<em>steps {<\/em><br \/>\n<em>script{<\/em><br \/>\n<em>try{<\/em><br \/>\n<em>powershell &#8216;docker rm -f yourprojectcontainer&#8217;<\/em><br \/>\n<em>} <\/em><br \/>\n<em>catch (err){<\/em><br \/>\n<em>echo &#8220;system-check-flow failed&#8221;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><br \/>\n<em>withDockerRegistry([ credentialsId: &#8220;b1fee946-b93a-46e0-ac78-abb78aea7cc2&#8221;, url: &#8220;&#8221; ]) {<\/em><br \/>\n<em>powershell &#8216;docker run &#8211;name yourprojectcontainer -d -p 1001:80 nxglabs\/yourproject&#8217;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p>step5: Lastly we will archive the folder by giving the path of release folder.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><em>stage (&#8216;Archive&#8217;)<\/em><br \/>\n<em>{<\/em><br \/>\n<em>steps {<\/em><br \/>\n<em>archive &#8216;bin\/Release\/**&#8217;<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><\/p>\n<p><strong>Output:\u00a0 <\/strong>We can get the output as below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-704 size-full\" title=\"pipeline staging\" src=\"http:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3.png\" alt=\"\" width=\"1581\" height=\"799\" srcset=\"https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3.png 1581w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3-300x152.png 300w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3-768x388.png 768w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3-1024x518.png 1024w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/1-3-800x404.png 800w\" sizes=\"(max-width: 1581px) 100vw, 1581px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-705 size-full\" title=\"console output\" src=\"http:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3.png\" alt=\"\" width=\"1585\" height=\"772\" srcset=\"https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3.png 1585w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3-300x146.png 300w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3-768x374.png 768w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3-1024x499.png 1024w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/2-3-800x390.png 800w\" sizes=\"(max-width: 1585px) 100vw, 1585px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-706 size-full\" title=\"output 2\" src=\"http:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2.png\" alt=\"\" width=\"1583\" height=\"791\" srcset=\"https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2.png 1583w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2-300x150.png 300w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2-768x384.png 768w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2-1024x512.png 1024w, https:\/\/nxglabs.in\/etech\/wp-content\/uploads\/2018\/08\/7-2-800x400.png 800w\" sizes=\"(max-width: 1583px) 100vw, 1583px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>This article barely touches the surface of continuous integration and deployment tools for .Net application using Dockerfile and Jenkinsfile. You can check out other cases for &#8220;<a href=\"http:\/\/nxglabs.in\/\">NXG Labs<\/a>&#8221; in this guide.<\/p>\n<p>Thanks for reading!!!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post describes how to\u00a0dockerise the dotnet application using continuous\u00a0integration and continuous deployment tool Jenkins. However, before trying this we need to set up Jenkins\u00a0pipeline. Through that, we can deploy the .net application automatically. Depending on this, we need some docker images for building the dotnet project. To get the docker images we will be &hellip;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[31,27,25,28,39,34,26,32,30,29,33],"_links":{"self":[{"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/posts\/477"}],"collection":[{"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":25,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"predecessor-version":[{"id":725,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/posts\/477\/revisions\/725"}],"wp:attachment":[{"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nxglabs.in\/etech\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}