Azure Pipelines : Build and Deploy ASP.NET Web Site to Azure VM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay welcome to this video where i'll explain you how we can use azure devops ci cd pipelines to build and deploy asp.net website or azure virtual machine i already have created a new empty visual studio sorry as your devops project and as you can see on my screen my devops project contains empty get repository there is nothing in this git repository i need to make my first commit thing second to second thing i already have created a virtual machine here this is my azure virtual machine windows server 2019 virtual machine i will just make sure that iis is installed in this virtual machine by running a powershell script this is a requirement actually you need to have you need to have iis installed for installation of uh or deployment of asp.net project so this single powershell command will do that meanwhile let's see how we can deploy a project here for that i'll go to my visual studio i have the sample asp.net 4 project uh this uses dotnet framework 4.0 what i will do i will just add this project to a git repository first by the way this project is already added to a local git repository let us just see if we can just uh make the changes here uh wait a second you can obviously use uh this toolbar or this toolbox team explorer toolbox to push this repository contains to azure repos directly from here if you have linked or if you have logged in into your visual studio with the same account or with the same email id as your as your devops account right now i'm using exact same uh exact same account at both the places in visual studio actually i'm using uh two of my accounts okay so if it is already there you can easily add it from here from this toolbox let's say for example this is the account which i have logged in into devops this is the account i have used to login just wait toolbox will load all my projects right here okay once the project is added uh once it shows the project here is the project name sample site is the project name basically let's click on advanced button advance button here i will select the project that i have created there wait a second what is the project name my project name is vm deploy demo okay fine so let's go to vm deploy demo here here it is vm deploy demo and my repository name is also vm deploy demo so i'm just going to publish this source code into this particular repository using this team explorer toolbox it was possible because i have logged in with the same hotmail account which i'm using for my devops subscription publishing has already started and it's done what i can do now i can just go and refresh this particular uh azure repo screen and you can see my sample project has now appeared here this is my solution file this is the asp.net website you can see the web config file right here and uh everything else is right there already yeah this is the assembly input looks like the recent changes i have done to this particular project are however not you can say uploaded there no worries i'll do that let's go to the changes i have added recently a default html page so home page sorry home page created so i'll just commit this change and let me sync this change with my remote repository let's see if there is anything to fetch nothing fine then let's continue with push operation with this push operation the changes will be now reflected in here let's refresh it one more time yes now the changes are reflected here i have got default aspx page and default aspx.cs everything is now ready all the contents are now uploaded there or submitted there meanwhile my virtual machine also has everything in place you will see my virtual machine now has uh ii server installed in it that's good we might need to rdp into this machine to actually proceed with the setup okay so i will rdp into it later on right now this is my project let's begin with the pipeline creation i'll quickly go to the pipeline i'll create a new azure pipeline for this project it's using azure repo this is the repository name and what i'm actually trying to deploy here is asp.net website so let's use asp.net this is the azure pipeline the default pipeline that uses yaml syntax everything is good but we just have to add one extra task here the task which is not generally included here is a task to publish the build artifacts so let us add a task to build or add publish artifact let's say i will just give it a name publish the website [Music] artifact then we need to provide the inputs and under inputs we need to provide the artifact name so i can just say it is sample site [Music] and then we need to provide the path to publish in path to publish i'm just going to say it's build a dot what was the normal file name i guess it is rtfact staging directory from where it has to actually collect it you can see it here the the default ms field argument if you can see here this particular build step is going to package your application at this location build a dot artifact staging directory so you will have to actually pick your artifact from the same directory and it will actually create a zip file sample site dot zip at the end of this build pipeline so i guess my build pipeline is now ready and i should now just click save and run please remember in azure repos it is possible to add the deployment step right here in the same pipeline but i prefer having a separate build and separate deploy pipelines so let's hit save and close and let's wait for the pipeline to be created just waiting for the pipeline i can see my pipeline has already started building it will take some time because it depends on availability of a build agent right now for this project i'm using microsoft provided build agent microsoft hosted build agent looks like build agent has been allocated and my project is actually going through checkout process now so okay done checkout is done now it's installing all the required nougat packages my project doesn't actually have any dependencies as of now but your real life project will have several dependencies and nougat command will take time depending upon how many dependencies it has to resolve and download looks like depository registration is done successfully there are no dependencies as such in this project so it should not take more than a minute okay done it has now started the visual studio build process this is where ms build a microsoft builder tool a command line tool that will use visual studio libraries and runtime to actually build this project okay it will compile all your asp.net pages and everything and once everything is compiled you will you will get the final artifact ready [Music] this is the log by the way you can see the log yep [Music] let's wait for this to complete now my pipeline has done everything it has done the publish task also it has created uh this sample site file container which contains everything let's just go back and let's see what artifact it has created it has pub it has one publish artifact called sample site and you will see it contains the readme file the command call script to actually deploy it on iis server and this is sample site.sip which actually contains my sample project that's fine i guess now next part is the release pipeline how do i deploy to azure vm now for release pipeline what i'm going to do is i will go to the pipelines and i'll go to releases let's create a new release pipeline which is responsible for continuous delivery and deployment very first thing i'm going to do here in release pipeline i'm going to select the pipeline template for virtual machine remember there is also an option available for virtual machine skill set deployment a very interesting feature that will allow you to deploy your application to number of virtual machines or deployed to vm skill set vmss instead of independent vm right now we are not doing that we are doing it for independent video so use this option iis website deployment this allows you to deploy it on virtual machine so select that very first thing i'll go to add artifact here i need to collect a build artifact and for build artifact i'm going to use this particular build pipeline as per my configuration here only the latest build artifact will be used for the deployment let's add this also i'm going to use this lightning symbol which will enable to enable continuous delivery and deployment what does it mean every time a new build is created deployment will automatically start and there is a similar trigger here after the release is created start the deployment immediately let's see the job here you first of all need a deployment group now right now i have not created any deployment group deployment group basically is a logical unit which contains all the local virtual machines azure virtual machines bare metal systems whatsoever are there so let's do one thing let's create the deployment group now when i click on the setting button the gear icon it will take me on a new tab this is basically a new tab your previous screen is here so let me add a new deployment group here i'll call it as your vm as your vm for the deployment let's hit the create button now you just need to select the operating system type you have got two options windows and linux in case if you choose windows this is the powershell script make sure that you use a check box use personal access token for authentication do not worry you do not have to generate any token as such token will be generated and placed inside the script for you let's copy the script to a clipboard and what i would recommend instead of directly copying and pasting it first copy and paste it to your local notepad there is one small problem that i have discovered earlier when you copy and paste it in a small notepad window we are using notepad here as a clipboard you will notice somewhere they have used unicode double quotes a special double quotes which will create a problem to me later on when i run the script inside my azure vm so let's replace those double quotes with a standard double quote symbol i guess the rest of the place all the double quote symbols and everything is problem not not a problem let's copy the modified script again now i'm going to run this script now on my as your vm oh sorry what i just have to do is now i'll just go to my vm let's connect it using rdp download the rdp file and open it directly with microsoft remote desktop connection tool connect here it will ask me for user id and password so let's use a different account my username is mahindra and this is my password and let's login looks like i wrote a wrong password for this time after you enter correct password it will ask you for a self sign certificate which is used for encrypting this remote desktop connection just accept the connection signing request certificate request and now you you should be inside your remote desktop by default on this windows machine if you look if you launch powershell window that powershell will be by default running in elevated or administrator mode so kind of easy here here it is my remote desktop as your vm remote desktop here i'll just launch my powershell windows powershell and once windows powershell is launched i'm just going to you know kind of paste the script that will register this particular machine as a temporary agent let's see what happens now the script execution has started already it will take couple of seconds for the script to run you will notice the script already includes the authentication token the personal access token was already included there this personal access token will expire in couple of minutes okay so please remember you have to do it immediately don't wait more than 10 or 15 minutes as far as i know it will expire after 30 to 60 minutes anyways i can see here as your pipeline has started already registering this particular server what we are doing right now is installing the azure pipeline agent okay enter the deployment tags i don't want any deployment tag right now account to use use the current system account i just press enter for all the configurations here starting immediately press enter to know just keep pressing enter for all those prompts except the default values and the server is now registered how do i know the server is successfully registered there if you go back to your release pipeline and just refresh this particular panel here you will see your azure vm deployment group will now appear here uh have you entered any tags no then don't write anything all the other values should be as as it is okay allow script to access authentication token this is actually not required as of now but it's okay to select this option right now my script doesn't involve any kind of tokens i don't need any kind of tokens right now as your web app manage this is the web app manage i'm just going to add it as a application user or you can use it as a windows application i will use passthrough and iis finding it will be just listening on port 80 and it will be registered as a default website yeah that's fine all the settings are good here it is it will just take the zip file and deploy [Music] that's fine i guess this is the default option we don't have to make any changes there okay fine the default template is good and fine let me just click the save button here and after we save this i'll create a new release manually later you don't have to run it manually okay later every time you make changes to the source code it should automatically trigger the build and deploy let's have a look at the release pipeline here it has already created the release but it's waiting for me to hit the deploy button manually so let me hit the deploy button deploy and let's wait you can view the logs okay the job has not yet started so just wait for few minutes now meanwhile i'll just note down what i did the steps were number one add project to as your repos get okay number two i created a new yaml pipeline or a new pipeline in yamaha format added a step to publish the build artifact [Music] okay this will ensure that in next release pipeline you are able to collect the application which was built by your build pipeline what i did next i created a new release pipeline and inside this release pipeline i have chosen a template a release pipeline template called iis deployment template okay now the very first thing in your release pipeline that you have to do is you will have to add the server groups okay now in server group i have added my vm as your vm now what you actually have to do is when you go to the server groups what you do is you copy the powershell script which is generated over there copy and paste it inside your target vm okay target machine and it's done now my pipeline is running you will see here it has already connected to [Music] azure build agent it is downloading the artifact and now it is going for iis web app manage yes now this step is going to run on my azure vf let's wait okay it looks like the deployment step has already finished and it has already done the deployment of this website okay that's great so let's do one thing i'll just try to go to this particular vms public ip address and let's try to access it from here looks like it is still showing me the default page on iis somehow the page is not built for this particular target environment i'll just get back into the rdp station here and let's see if it has done the deployment correctly [Music] i will show you where the project will be here should be in my c drive i need pub ww root and this is the default dot aspx i was referring to this is the default ii start pages and inside the bin directory there is sample site dot dnl dln files are right there looks like this project actually doesn't contain those html pages uh sorry those uh modified pages basically d e f a unt default.aspx giving me a page not found error okay let's try to just rebuild it what i will do is i'll just make some changes to my project right here this was my default page and then the changes i will commit them now home page sorry editing push these changes to the repository to the remote repository and then push them back every time you do a push make sure that you first do a pull operation to make sure that your contains are in sync let me just check if my pipeline has already triggered a new build and to do that let me just go back to the vm deploy here and what i will do i'll go to the pipeline and i'll try to check if pipeline has already get triggered yes my pipeline has already started and you will see pipeline is already in progress it's already doing the builder job right now already started with the build job okay project is getting built now visual studio build has already started [Music] okay okay and it has produced one build artifact because i have set up the continuous release pipeline let's go to the release pipeline and see if it has already created a new release a new release release 2 has been already created there and it has already started the deployment okay so deployment is already in progress let's see as your web app deploy has already started it has done the deployment now yes let us try to visit the website again there's some problem with dotnet framework the framework that i have chosen probably is the very old version okay that's it this will take your application to azure vm maybe i'll just go to the vm and check if it has the required version of dot net framework server manager and add rules next role based next and let us add web server inside web server in application development i'm going to add asp.net asp.net 4 by default this will add asp.net 4.7 but i guess 4.7 is already backward compatible with asp.net 4. my project is using asp.net 4. next and install you need to actually pre-configure your target virtual machine to support the dotnet framework for your project installation will just take another minute and probably you should restart your machine after you install any new component into it okay already started you can even close this window installation will not be interrupted even if you close the window it will keep on running the installation in backlog so yeah it's working now so originally when i deployed my application i deployed it i deployed an application with asp.net 4 but unfortunately for my uh target server was not actually compatible or it didn't have asp 4.x installed and that's why the page was not loading but now my application is working just fine just as a final quick check i'll do one thing i'll go and make a small change here style is equal to and then background color tl okay i just applied some small css and let me just you know kind of push these changes now to my repository let's commit the changes i have just added a background color okay commit all and let's sync this push now after the changes are pushed my pipeline will automatically get triggered so what i will do now is let's go back to the pipeline page here and let's wait for it to create a new release it will obviously run the build and then it will run the release let's see if build has already started yeah i can see a new build has already started and you will see here the same comment added a background right so build has already started it will take another minute and immediately after build is successfully uh completed it will start or it will launch the release pipeline as well this is example of ci and cd continuous integration and continuous deployment okay let's see how far it has gone through like it's now in vs build stage building the project depending upon size of your project it will take some time to build your project it's running okay and as soon as this particular pipeline is done its job as your devops will go to release pipeline because of that release trigger and here release pipeline has already started in case if you want to see where exactly i set that trigger here is the trigger continuous deployment trigger this will make sure that every time this build artifact changes this release pipeline is automatically launched and this lightning symbol here pre-deployment condition will make sure that after this build artifact is ready and release is created it will trigger the deployment as well okay now let's see if this is already done i'll go back to the pipeline i can see release number three has been created just couple of seconds back if i now go back to my virtual machine here and refresh you will see the background color is applied that's it this is how you deploy your application asp.net application from source to azure vm thank you
Info
Channel: Mahendra Shinde
Views: 350
Rating: undefined out of 5
Keywords:
Id: BpCwQp-ABcM
Channel Id: undefined
Length: 31min 23sec (1883 seconds)
Published: Thu Oct 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.