Step by Step - Use Azure DevOps to Test, Build and Deploy an API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay so imagine you've commit your cord to github and that automatically triggers the build test packaging and then finally the deployment process into production on Azure within a matter of minutes so as good doesn't it so that's exactly what you're gonna learn today in this video completely step-by-step as I take you through as your DevOps pipelines [Music] well hello again we are ever you are when ever you are with a my Melbourne Australia as usual laughter think about that and where am I it's March 2019 so I hope you're happy and well whatever you happen to be we've got a lot to get through in today's video so we're gonna get cracking on just say if you liked the video give it a like and if you haven't done so already please subscribe to the channel and remember to click the little notification bail icon and you'll get notified whenever I put up any new videos other than that lots to do so let's get started okay let's get into this so yeah this is a step by step into building and deploying a REST API with as your DevOps so when done you'll understand what is a CI C D pipeline what is as your DevOps and some alternatives how to connect github and as your tours your DevOps it's a bit of a mouthful how to configure as your DevOps pipelines which is really the main part of the tutorial in this video and then how to continuously deploy tours Europe which is I guess really included in that last point and what you'll need to follow along with this video if you want to do that you can just watch obviously you'll need a text editor and recommend es cord and dotnet core SDK installed on your workstation postman or really to be honest with your web browsers fine just to test the API and get hub as your and as your DevOps accounts which are all free for individual sign ups there are some paid plans obviously but we'll cover those from the relevant later on as we move through the video and about 30 minutes of your time now it would be advantageous if you know about some of these things because I can't cover them in detail as part of this video I just don't at the time so unit testing get dotnet core development and as your don't worry the video is completely step-by-step so I don't skip anything you you can follow along even if you don't know any of that stuff but for example get is in my view of quite a big subject and if you've never touched it before then you may want to do a bit of side leading on exactly what it is but don't want to we cover it all step-by-step here just can't go into the detail okay you will forgive me otherwise the video is going to be about five hours long toward the time so what is CI CD well it stands for continuous integration continuous delivery most usually but you may also hear people use the term continuous deployment so as it says on the screen there shows you on the screen they are the kind of steps and I cannot pipeline almost depicting on what a continuous integration and continuous delivery and continuous deployment are so continuous integrations really the the art or the practice of multiple developers committing code to a branch and having that chord built and tested to ensure that the build and the branch the chord branch remains healthy so you've got multiple contributors making sure they don't break the the codebase basically that's what continuous integration is and it involves building and testing the codebase so we will cover that in this video continuous delivery is the next bit in the pipeline our next bit in the chain and it really is talking about taking that build that successful build and packaging it ready to be deployed into production now we don't actually deploy all the way into production it's just literally ready to deploy at touch of a button and then finally continuous deployment is taking it that one step further where you actually there is no manual intervention from the point where you commit code to your repository the pipeline will run and will deploy all the way through to production now that are very I there's not that many organizations or they're certainly fewer organizations that practice that mainly because business and IT remain relatively separate beasts and IT are responsible for the build and the packaging and it's not ultimately their decision to release software into production that's a business decision so very few put very few organizations are at that level of maturity with a confident enough to deploy all the way through the production so most organizations take it to the point of continuous delivery and then there's some manual process where the greenlight is given to deploy into production so that's the difference now in terms of this video we are actually going to be doing continuous deployment so we're going to ultimately commit chord changes to get and that's going to filter all the way through our pipeline and ultimately will end up resulting in live cord being deployed on tours your so it's pretty exciting here's a depiction of the full build payment bill payment of the full CIC the pipeline and it's taking all the way through from planning what you're going to build all the way through to monitoring it when it's released into production you may also see it depicted there's an infinite loop if you're getting into DevOps that's often our diagram that you will see thrown around quite a lot in terms of what we're going to be focusing on in terms of our pipeline in this video we're going to be looking at cording building testing releasing and deploying we're not going to be going to be setting up some sample pod cord projects but they're really just going to be the template projects that you get with dotnet we're going to be doing very little actual recording as part of our a as part the cords part the pipeline we will then be committing those changes to get and github and then as you have their bops takes a lot so actually the next slide shows you this and a bit more clarity so when we talk about cording yes obviously we're talking about the practice of writing code but what also in terms of our build pipeline on our CI CD pipeline or talking about the cord repository software you actually put that cord as part of your continuous integration process kicking off and committing code to github is basically going to be our trigger to start the pipeline and that's good as your DevOps takes over and it's going to build our code base it's going to run our unit tests it's thing going to package it ready for release and then it's ultimately going to deploy it to Azure now just a word as your DevOps also has a repository feature will show you that in a bit we're not really covering it in much detail here but technically as your DevOps could do everything from the cord all the way through to the release of the repository all the way through the movies but as you're still as our cloud platform and then just to just to give you some point of reference that I'm different code repositories available get labs I've put there as also bet bucket in terms of build sours I've put cycle CI up there there's other ones like Jenkins or where our car there's a whole raft of them and all the servers are multitude of cloud platforms Amazon is probably the the other big player aside from is your expose you have Google Cloud that don't seem to it doesn't seem to be as strong as Amazon and Microsoft and in the cloud space and you can even if you really want to get into more detail each one of those components build test and release there's also specialized technologies that will deal with each one of those segments we're not going to delve into that detail yeah so done enough talking right it's got another video all right so I'm going to start be s chord and I'm going to use the terminal with MDS code just because I like it it kind of follows the Linux Kinison tax so just change into your working directory I can type that'd be good and yes so first of all we're going to create our solution directory we'll call it simple API solution so that's going to contain our two solution projects one is going to be our REST API one's going to be your X unit project so let's change into into that folder and within that folder we're going to create two other folders one called SRC for source and the other one will be test for our test project so do a little directory listing I'm using LS command which is a the next command if you know if you're using Windows command line use dir so cool we've got both those projects probably bottles for the setup though just in case you're interested I do have an article on my blog I promise this is the last time I will try and push this down your thought and it does actually have instructions on here I'm expectedly going through now and it goes through the directory structure on how to build what we're going to build so if you rather do that you can do that obviously I know some of you prefer videos so let's keep going with that so we're going to change into our source directory and we're actually going to scaffold a new project so Nate yeah before we do that if you just do dotnet - - thousand it will tell us what the option were using saw at the time I'm making this video the versions to point to after you get an arrow there then you haven't installed their net core framework so just Google install.net core and follow the instructions I actually if you're doing it on Linux I've got a video on how to do it on a bit into Linux anyway back to what we are trying to do so up key to note - the executor that's why it's not there so dot me at you and then what type of project do we want we want a Web API project again the last video that was on Web API so if you want a lot of detail on how they work look at that video we're just going to use the scaffold that cord saw dotnet new web api will go away and create a project follows wonderful now if we actually change into the source directory or we were already in their memory it created a folder called simple API after the name of the project and we change into that you'll see there's a whole raft of files and folders in there and if you want we can do thought net build don't know why I'm doing it on their build build it and it should hopefully build okay it'd be quite scary if it didn't so let's change back into our solution directory to our listing again so we're back in our solution route this time we're going to change into our test folder doing a directory listing there's nothing in it and in a similar way we're going to scaffold our X unit projects or dotnet knew your project in fact if you just do net new it will give you a list of the different project tapes you can create so we're just going to do dotnet new X unit and then the name we're going to give it is simple API dot tests so the name of the project is basically exactly the same as the name of the project we created previously with a dot test prefix that's kind of standard naming convention for your unit testing project so let's just do a dotnet building that as well it should build okay well we're not in the folder so we didn't actually change into the formula that's changing for the full list there's our project there and if you didn't build it should build if you do dotnet test it will actually run the unit tests and the earth and there was one it says there's one test and here that's basically an empty test but we will come on to that in a minute no change back up to your root solution directory sore directory listing we're back at the top we have our two projects created what we want to do now is create a solution file that basically ties the two projects together now this is really only there's a couple of reasons why you would use that one if you're using visual studio look like a solution file another one I'll show you in a minute why I like to have a solution file so to create a solution file you simply type dot net new SL n name and I call it simple API s alone and that should create a template solution file so if you do a listing though we have our two folders and we have the simple API solution solution file now what we need to do now is actually add our two project references into this file so this is a bit of our along command line so I might speed this up [Music] so basically what this was doing we were adding these two projects to a solution file now the last thing we have to do is we need to add a reference to our API project inside our testing project so basically our unit test project is going to test of our API project now in order to do that it needs to know about it so we need to add a reference to our API project inside our unit test CS proj file so in order to that you can manually edit the test project CS pod file if you want or you can use the command line so we're going to do that now [Applause] [Applause] [Applause] okay so what we can do then is we can then open a folder to open our solution folder and what this will do is open our solution so if we go into our test project here is the CS plot file you should see a reference here to our API project fantastic okay so one of the things I just wanted to show you before we move on is if you get a terminal backup and if we take dotnet build what in our mean well then I mean solution rule that if you take dotnet build because we created the solution that will actually go off and build our two projects which is great now we've already tested our action at project by doing dotnet test we just want to test that our API mean API project actually runs before we go any farther so let's change into that folder don't need the asterisk appear and change into the main folder and if you do the dotnet run that will run our API and it's started on either one of these let's take the non-secure one actually let's take the secure one because it will redirect us control see then and I think I've got postman running no I don't get postman on yeah you can't just paste that into are you into our web browser as well if you like but we'll use postman they stand here and then the full path to one of our action methods is API values so if you actually go pop back to our main API project and go into the controller you can see here the paths to the various action methods not going to go into much more detail that doesn't make any sense watch my previous video there we go so we've done a get request to this address - this URL here and this return back value 1 in value - if we change the signature its returning back something else that number can be anything that can be arbitrary there you go and so basically that is calling this this method here okay cool so that all looks like is working so ctrl C to stop ourselves from running okay so what we want to do now is pop over to our unit testing class and we're going to actually create a test that tests a let's see what will you test we'll test this test this action method here we'll see and check to see what it returns and we'll unit test that and we'll see what we get so let's go over to our unit test project go into here and we'll create new test within here know again this is not a video and unit testing so and you typically create a new class for a new suite of tests that you wanted to implement but I'm just going to put it in here for for quickness so the first thing we want to do is we want to add a using directive at the top and make reference to our controls folder so we want to make reference to basically what's contained in here and then within our class we're going to create a values controller object and spell it correctly [Applause] we're going to test against so you will create fact which is basically effectively a test create a test method and we'll go we'll give it a verbose name see get three tons my my name so you typically name your test what you expect the positive result to be if you like so we're going to create either ton value and we're going to make that equal to ever our controllers get method the tons now in here we're just going to arbitrarily pass in any integer it doesn't really matter what that is bringing back or what that number is then that's complaining I don't know why that's feeling we'll come on to that in a minute and then bill I set up equal my name in is equal to the return value okay so basically what this is saying is we're creating a new controller that's based on our API controller we're calling a new method that's effectively or test we are putting into this return value variable whatever our controllers get methods with tons and we're just passing in an arbitrary one and then we're setting that that value is equal to e string which happens to be in my name no this is complaining I know why it's complaining but let's just let's just jump in here and clear this and we will move into our let's move up to our solution directly moving too fast with them to or directly and we'll do a dot net build its building okay and we'll do a dot net test this should feel actually will where you'll see that you'll see this let's just try that again so you can build field yeah again now so because we haven't saved the file and blah blah blah and basically what it's seeing is that we have a missing reference to this Microsoft asp net core NB c-- suppose copy that and what we'll do in our some in our unit test project you will simply add a package reference to this package here and in fact we can be a bit cheeky and we can just copy whatever is in our REST API project so let's just copy this and we'll put it into here save that off let's just see we had some depends you sort of a wing do as far as fantastic and if you go back here I will bet this should build have one error what is the problem yeah okay you have to capitalize that don't you just love okay typical so it's all passing so I'd small carrot to the herbage my fault and also the unit test project doesn't have a reference to ESP the asp net core so it was throwing up an error so if we then run our test now so an our unit test project dotnet test we should have two tests we do and a test run field which is what we'd expect so we have a total of two tests one passed which is our empty test and one field now the main reason that field was we're expecting this return value when in fact if we jump over to our controller it's returning this so it's a very simple fix built on this for my cord now I appreciate this is a very simplistic test but we're testing what our control we expect to get back from our controller we're just hard coding the values in but it's a valid use case and I just wanted to demonstrate in terms of CI CD pipelines how unit testing please and that so we've saved that off let's run that again there we go so we've got a total of two tests to if pass as you a field that's all green life is good so you'll be pleased to hear we've set up our cord projects we're going to basically that sir we're going to tinker with them ever so slightly but that's basically that setup so you won't have to watch me do too much more typing I'm sure you'll be very pleased to hear so next what we're going to do is talk about source control so we're basically going to put our solution that we've just created we're going to put it under source control and I'm going to use get to do that so that's actually going to do a little bit more typing but not not that Babur so back to our command line and let's change into our look let's change into our main solution directory do it clear the screen and do a quick listing just to check that were there so should be fairly familiar to you we've got our source test folders and us or file you'll also see there's a adoptee escort folder that's just for the VA squad convicts or bill that mind in just one second so get not going to go into too much detail about what get is but basically it's a personal control solution that's used basically used everywhere so we're going to use git and then we're going to use github as our clothes the ocean so first of all to get at the command line - - browser just to make sure it's festive and I've got ya to 0.15 installed that's fine if you get an error message then you'll need to install get you'll have to Google how to do that it's pretty straightforward again my video when setting up a Linux don't make or box takes you through that for up into so we're in our solution directory what we want to do is initiate or get repository so it's very simple let's get in it if we spell it right get in it there you go and what that does is you can see here boom straight away vs cord has actually responded to that and let's change colors and get 64 files that are pending some changes so very good the next command you'll want to do is a get status and these files have not been yet added to a our source repository now before we do that there are certain files that you do not want to place under source control so what you will do there is you will create a get ignore file so you will do a new file called git ignore and basically it's a file that's just going to tell get there are certain things you ignore now I am definitely not going to take this in because it would drive you absolutely insane so back over to the blog I have provided a sample get ignore file I am just going to cut copy and paste from I'm going to paste it into my get ignore file here there you go and we'll just save that off so that's the I hate cutting and pasting I like doing things step by step but for something like that there's a little way on earth I would hate that so you're more than welcome to use that you there's other ones available that you can use so we've got to get ignore file we have initial initialized or get repository and there is a hidden folder now but then you are a solution folder called dot get that contains all the tracking information that can get quite big so just be warned on that so we want to now add our files and folders under get control so we'll do a get add dot to add everything you don't need to do a git status by the way I just like to I just like to do that to see how things are tracking great and then finally you do a get commit such as to stage commit process we'll use the dash M switch to put a little message in and we'll just say initial commit and do it gets theaters again I'll say here there's nothing to commit we've got a working clean tree on our master branch now again you're not using it before you and you don't that makes no sense to you you're going to have to go into a little bit everything but basically it's a two-stage commit process get add get commit great so we've just set up get locally on our workstation that's wonderful and you can actually set it up get as part of our ways our team and set up your dough and get servers and all that stuff that's wonderful but what we are going to use and what we need to use and recommend that we use as part of using as your bear box is use github now github is basically a cloud get solution as I mentioned at the start so what we need to do now is let's go over to github so here's my github page github com if you're not going I can't just sign up for one now all the projects I've done previously for my other videos are on I'm going to create a new repository to hold this project so click on new and I'll give it a name I'll call it simple API and we're going to make it public remain remember that a bit later but we'll keep it public that's fine and we'll just create a repository cool now this is actually the home page of this repository now because there's no chord there which we will rectify in a minute it gives us some instructions about how to basically use this repository now this set of instructions here as you can create a new repository at the command line these commands here should be very familiar to you because I've just done these on our workstation so we don't need to do these get in it get ad and get commit steps we simply need to do these steps here which is pushing an existing repository to the command line so I'll copy this one as well I lied I'm doing a little bit more clapping let's paste that in there now all that's doing is it's seeing what adding a remote repository which is on the github repository we've just created as part of our solution so that's all it's doing is just creating a pointer and then finally all we need to do I really shouldn't copy this but I will is actually let's not do that let's tape it so let me just take that and get push you origin/master now we'll be using this command an awful lot throughout the rest of this tutorial and basically it's taking our local git repository pushing it up to the cloud no quick sidebar if you get some if you're using Windows and you get like an authentication error here then you're going to have to update let me just get the name of it it's called something like Windows get a fan to cater let me just get that for you anyway you can see here that we have pushed up our code to our github repository so if we move back over to github and we refresh this you will actually see our court project has been pushed up to the to the cloud and you'll also see that there is no vs cord fold up being pushed up because I'm going to presume at this stage that it was part of the ignore files that they had and I'd get ignore very good okay so it can even drill down here and you can see basically see our project so that's wonderful our cord is now available I'll get up so now we want to move on drumroll please we want to move over to Azure DevOps finally he says finally you see okay and can simply find that devdas eurocom if you're not going to count create one for free now I've got a couple of projects already here we're not going to touch those we're going to create a new project if you just signed up your home page will look slightly definite but ultimately you'll have a create button create project button on your home page so create project we'll give it a name let's call it simple API - since I've already got one there already now remember when we selected our work when we created our git repository it wasn't that long ago so you should remember and we could choose whether it's public or private you need to make sure the visibility here is the same you can't have a private as your devops project and a public github project so we need to make sure the are the same just an advanced make sure your version control which it defaults to get is set to get and the work item process is joe that is not going to be used as part of this project this video so it goes off and it creates a new project for us right now here we go simple API - now there's a dashboard or a list of things you can do that on the site here we are only going to be dealing with the pipeline section here I mentioned there's a ripple piece of functionality within as your DevOps that you can actually push record - if you want but we are using github instead so that's all good so we're only using pipelines so let's click on pipelines now the first pipeline we want to build or create is a build pipeline so we have no pipelines are told so let's create a new pipeline now first question asks your Spears record there you go you could slate to perform as your ripples we are going to select a github now I have already linked my Azure DevOps account to my github get hobbit github account the first time you're doing this you will probably get some if you click on my quarters and github you'll get some challenge response to enter your credentials for your github account so that as your DevOps can I say indicate because I've already done it I don't want to undo it it's very very simple as not much to it at all you just have to put in your username and password but you will get that challenge a the first time you did it because I'm already done it and it's brought back all my repositories which should look quite familiar to you if you remember what was on my github page so we are going to select our simple API repository and as your devops goes away as you can see here and it cannot pass as the solution and it looks to see what is it and it suggests some pipelines that you may want to use off-the-shelf so fantastic asp.net core that's what it's recommending and i'll good with that so we'll select that know as your pipelines thought why am L or yeah Mille as I will know refer to it if you're going to take something away from this video take away as your pipelines yeah Mille this was the thing that consumed most of my time preparing for this video it's not difficult but it can be a bit fiddly it can be a bit finicky and it's if it's something is going to trip you up this is what will trip you up so this is the core thing that we're really going to be concentrating on and it all it is in terms of your build plate thing are the steps that you want to perform as part of your build pipeline now the only one you really need to look at here the others are fairly self-explanatory are the this five-step year which is really just a dotnet build commanders if you're running at the command line and it's building a release a origin and the display name is just four of our boss output as you'll see in a minute so that's all that's doing at this point in time it's going to take that cord and it's going to build it it's not going to test that it's not going to package it just going to build it so let's save and run that before we do it's prompting us to see where do you want to put this as your pipelines you Hamill file now it's seeing you can create a new branch or you can commit it directly to the master branch which is what we're going to do source even one remember that because it comes in comes back to betas in a little bit so that goes away and actually kicks off the pipeline the pipeline is now going to start to run would have manually configured that it's not been automatically triggered it will come on to that in a bit so you can see here on the stream it's finding an agent to actually execute the pipeline it's got one and the agent is going to start working on our on our build and you'll see the steps executing in the amyl file there as it moves through and you can see here as doing the dotnet build release which is the boss output that I was talking about and it just gives you some details on what that is okay so you can see here that the the pipeline has completed them here are the various steps that it has gone through in order to complete the build one thing I will just show you if you jump back over to github and we go back to our let's go to repositories and we click on this what you will actually see is that has added as your pipeline's gamal to that repository be all that in mind in a minute now so what we've basically done is if you go back to click on builds here you can see we have one build pipeline and one successful execution of that build pipeline which is fantastic but it was manually triggered so if we then click on this pipeline again and edit pipeline and that brings up a Yael file again but I just want to assure you this triggers section here and this tells us what will trigger the pipeline and basically that one of the triggers at the moment is anything that's committed to github this repository here will trigger the continuous integration activity and the build pipeline will kick off so let's test that theory let's just select our builds pipeline again minimize that and let's go back to our code base let's go into our API project and we will select the startup class now I'm just going to take this out not nicely suggesting this is a great thing to do but I'm just going to take out anyway just to invoke a change within our cord we'll save that all that was doing was enforcing HTTP redirection so let's do get status and we can see here that there is one file that's been modified that is a startup file fine so they wanted to add that for a pre commit we do a get status again again you don't have to do that but it will just say yes it's been you know staged for a commit and then finally we do get commit as a message and this time we'll saved HTTP read Direction fantastic hit enter do a get status nothing nothing left to do so all we need to do now if you remember what is get push origin master and that will push our git repository back up to github no there was a bit of an issue it failed the reason it failed if you actually read what it says here it says the updates were rejected because the remote repository contains work that you do not have locally remember what that was yes it's the as your pet Ling's yeah more fail so what we simply do is get pull to merge the changes from the github repository down to our local upholstery and it kind of marriages and can it checks to see you know what changed in both places so we have a consistent copy so we then simply have to do a get push origin master once again and it should work this time and you'll also notice that we haven't as your pipelines yeah and the file following the get pull and in our project there you go and we can now edit that MDS code so we did the get pull brought down the amel file resolved the differences between the two repositories and then we've pushed up our change which was to take out HTTP redirection from our project now if we jump over quickly to as your devil what you should see is a trigger build so you'll see another build being triggered hopefully anytime soon there we go on your build click on that and you can see it's building now that should succeed so you can see that that build obviously succeeded just like the last one that was just a minor chord removal but the point being that it was triggered from pushing our chord up from a rock station which is which is wonderful what the build pipeline isn't doing as I said they are they are on is that it's not running our unit test suite now a build pipeline that doesn't do any testing is really almost kind of worthless because it just means you're effectively pushing cord you could just be crushing pushing cord into production without doing any kind of testing so it's absolutely key that you do that testing component so we're going to rectify that now and clearly do that is in our Yanam file now because we did that get pull and we pulled the Yama file down into a project we can edit in vs chord or alternative alternatively if you prefer you can do it directly and as your dev ops in the web browser so water or as your pipelines fail and we're going to actually insert a task before our build so we want to run the tests before we run the build which makes sense you don't want to build a name and then test it so I might fast forward I will type this in but I might speed it up so you don't have to sit here and watch me typing and I'll explain what it does when I've finished [Music] okay hopefully didn't find that too painful basically we is it's kind of interesting so they use these things called dot dot net core CLI commands basically so you can see down here we use the script command to run a dotnet core build but instead for testing and this is just through the research either that requires you to use this dotnet core task type that then you then pass in commands so passing in the command tests so it's like typing dotnet tests and you can pass in a project flag and we're basically just telling it that we want to run the tests in our test project and I'm just using some short chords or shortcuts to get to our project path and then we're just passing in the build configuration which is release and then it will assuming that successful it will then skip on to the build components or I've saved that file let's do it get status again as expected we have one more defied file which is your pipelines file so let's get add that I can do a get status just so you can see what it looks like and then we're going to do a git commit M switch with some details you'll see updated yeah will file to run tests now hopefully I taped it correctly so that's all good we do a get status it's all good we then do a git push origin origin master which pushes it back up to get hub which should trigger a build which should now execute our tests or fingers cross so that pushed up okay if we go over to get hub and do a refresh you will see that there's your pipelines yeah no file should contain my changes it does that's wonderful so that's being affected here and then we click on our build pipelines once once it's registered that commits that push then it will trigger another pipeline build and hopefully it will run our unit tests and hopefully this should be successful so yes if you just go back down there well that's that's what can we change back into our test directory and do a darknet test our tests pass locally so they should certainly pass on the build server long as your DevOps so we can see we've got on your build and it's starting to build so let's see what happens okay so our build has completed and it's green which is a very good sign so if we click on that you will see that there is another step in here dotnet core CLI which is the step we added you can see here it took almost two minutes to run so if we drill into that you will actually see down here that it was a yeah it was executing our test so you can see here as it sure does on a local desktop total it to a test to pass your field fantastic and even which is really nice actually gives you a nice dashboard that you could put up on our you know plasma screen of a LED screen and your team environment actually shows you the status of the test outcomes and you can actually look at that the old baby nice so what we've just done is we've just added the step to our Yama file that enables us to run our unit test suite next what we're going to do is we're going to break our unit tests just to prove that's it will be reflected the backup and as your dev ops will do that makes so let's break our unit test so we can do it quite simply by going into our API project and going into our controller and simply changing the value that we're expecting in our unit tests or change it from my name to the name I always wish I had which was the name Homer gave himself in one of the episodes where he changed isn't him to max power I thought I was pretty good you know where the Simpsons were definitely at a peak so we don't know solution the full bar let's do a dotnet build that will build both projects should they should both build so even though point me Akira is the cord is still okay the project is still building there's nothing syntactically wrong with the API project that's still fine but if we change into our testing project let me run the tests they are the darknet test it will feel okay so the cord is fine the builders passing but our unit test suite this feeling okay I'm just going to push that up to as your dev ops so let's change back into our solution and directory do a get status of course we'll see you values control that has changed so we'll do a git add everything and we'll do a git commit and broken unit test do a sad face not with a wink just a sad face and we'll do a git push origin master now Oh spell that engine let me go now you may ask and it's a really good question what why would you push cord up to your repository if you've good feeling in it tests it out right you wouldn't do that we're just doing it as an example that being said there may be situations where you're working on an actual project and you can't run all your unit tests because maybe it's a huge piece of code so you don't want to run all your unit tests you can run small unit tests and either individually or as you're part of a group and so you may only be testing a certain chord and you may really be testing certain running certain unit tests but the chord changes you've made me break or cause a unit test to feel something else new chords so you may be unaware that you've broken a test because you're maybe not running all the tests locally and that's why something like a build server or CI CD pipeline and the cloud is really useful because it will run the entire unit test regression suite and pick up an hour okay so if you move over to as your DevOps pipelines you can see that yes our CI CD pipeline is in fact being kicked off again and it's running through its steps build and test steps and obviously when we comment it then it comes to doing the unit testing component it it should feel so wait and see wait for that to happen just so you can witness it and there we go it's failed as we expect that if we drill into it you'll actually see the step that it failed that and that is the step supplier surprise we are we are running our unit tests or we drill into that it will probably give us a bit more detail yeah on dotnet build on record one if you go back to a dashboard it will also display the issue so I get to a test once filled and we can drill down and have a look at why that's the case so I just wanted to show that that was the case now actually before we move on important is we will just run out this back so passing state and we'll just recommit the cord back up [Applause] but we won't there this time watch the the build pipeline you I'm sure you have confidence know that it will air pass and let let's do a happy face this time smile okay and then we'll do a get fish okay so just wanted to show you that the testing is a critical part of it feels in the pipeline then the next step won't be executed in this case what is the next step going to be a next step is going to be packaging up a lot of successful build and packing up a successful build ready for deployment so let's do that No so yes let's do the package part of the pipeline and you can probably guess where we're going to make a change and I build pipeline yeah that's right we're going to make it as you are pipelines yeah more file now you can see here we have the original script a component that was in the file which is basically doing our build we added this task here to perform our unit testing and now we want to add our packaging component now I actually did refer quite a bit to the Microsoft documentation as an MSDN article now I've actually linked to this article for my blog post and as a section on not building not varying tests connecting code coverage packaging and delivering your cord so basically I I followed the instructions here now I'm going to take this cord in I'm gonna fast forward through this through this bit the video while I tape it in so they come taping super quick I'll play some interesting music and then once they finish taping I'll come back and explain what's going on so get ready stand by here we go [Music] okay so that was probably as painful for you to watch as I was for me to type I probably should they just pasted the core then but hopefully as you as I type that you kind of understood what was going on so basically we created two tasks effectively the first one is just a dotnet publish command which you could issue at the command line yourself and after the we do the publisher should basically packages up we then zip up the artifacts ready to be actually published so the last task is this publish build artifacts command and that actually makes the artifact that web zipped up and built effectively ready to be consumed by our release pipeline so let's save that we have saved that let's push up to github it'll get or trigger the build process and we'll look to see if it's all green if it's all green then we can move on to the next stage so let's do that now so again standard workflow there are we got in our solution for bus we get status there's only one file being altered as your pipeline's fine so we add that or commit it you get used to this by now and our message will be updated if your pipelines to package build cool and then we will do a get push origin we're gonna spell it correctly master okay there we go it's getting pushed up to github let's jump over to is your DevOps and see hopefully fingers crossed again take the hen correctly that the whole pipeline runs and builds our build artifact our release artifact should I see okay here we go back into pipelines back into builds so well well this is building one thing I forgot to mention as we were covering this the amyl file is in this task that we've added here which is a publishing task we are issuing a published command via the dotnet core command line cool this second I guess argument or switch your publish Web projects false I spent a lot of time struggling with my the step feeling and the reason that was feeling if you actually dig into the failure step was because for some reason it assumes that it's a web project now possible because it's an API project that definitely it does differentiate slightly between the two I think if you are specifying that it's a web project that expects certain directories to be there with an API project those directories are not there I think that from memory that was the the complaint the error on that it was giving so you have to if it's not a web project which this one is not you have to explicitly specify publish web projects as false so take that away and hopefully save yourself two or three hours that I spend trying to figure out exactly what the problem was the rest of it again is fairly straightforward and of course this last step your zip after publish true means we have a zip file ready to be used by this last step which is effectively a publishing artifact step so let's jump back over here fantastic we've got a green tick let's just look at the steps saw published artifacts exceeded the publish step as well actually succeeded too which is what I was talking about and that was the step that was feeling when I did not have that and forgotten what it is now and I didn't have this publish web project switch in there so good news that is our build pipeline complete with that final packaging step so the next thing we need to move on to is our release pipeline that will take that artifact that that zipped up and published and push it to as you know before we do that we need to set up a resource on as your so let's jump over and do that no alright so let's move over to as you are now I have it I'm a bit Mart but if you just go to Portland dot as eurocom that will take you there I presume from memory or from memory if I'm correct if you don't than account it will just take you to the sign up page sign it sign ups for individuals are free and you'll get a number of services free for the first twelve months and there are also a number of services that are just free going forward I think you may need to put a credit card in after your Theor TV so J speedy that has expired but don't quote me on that it's been a while since I've done it now with Azure it's a vast subject literally into you know 20 seconds as your as a cloud platform that allows you to quickly provision resources or resource can be anything from a virtual machine instance to a database to an app and we were actually going to create an app instance an API app that just sits on Azure so we don't really need to worry about is it sitting on when those are certain on Linux or anything like that we do configure the kind of hard world that we want the kind of performance we want but we don't really need to worry about anything like that it's much more detail and it's instantly provisioned for you now you'll see the plan that we are going to pick is a dev test plan and we get free compute minutes for this particular thing so it shouldn't generate any costs on your account and typically what I do once I finished with the resource when I'm finished playing with I'll either stop it or delete it so if you follow this as I'm going to show you it shouldn't generally any costings on your account so over on Azure we have a dashboard with a number of things we can create sorry I see you are you could create a virtual machine you can create a sequel database you can create all sorts of stuff so we're going to create a new resource for ourselves and the one that we want this API app so if you start typing this is the one we want API app and it gives you a bit of the herbage about what it is so we all click on create so we'll give our app a name so let's just obviously after myself again as a narcissist and we'll create a new resource group every time you create something in Azure they want you to put it into a resource group and it was all scripted basically just there was a group of resources so I already had a resource group there called layers jacks and so I'm just going to put it into that existing one if you doing this completely from scratch just type in anything you want there it's not really that important as far as this tutorial is concerned know what is important is this service plan so let's click on that and it's defaulted to a particular service plan a plan that I don't want it's too expensive for my tastes and it's also in the wrong region in the central us so I'm going to create a new plan so I'm gonna call it cheapo plan because I want it to be free I think you aren't allowed spaces not right okay there you go location so you can choose obviously where you want this resource to exist Microsoft have a number of data centers around the world and so just pick the one that makes more sense to you you possibly want to pick the one that we are the most traffic is going to be in essence since I'm going to pick a Straley of south east because that's where I am and then possibly the most important thing is the placing to you so if we click on that it will take you over to the different tier so you can have a production level offering and you get various you know catalog of things you can pick from there how much memory you know how BIG's the CPU all that kind of stuff you can even have something that's completely isolated on its own so there's no there aren't any other and subscriptions are utilizing that hardware we're gonna pick a dev test plan and again even within dev tests there's a number of placing Till's within that we were gonna go for the f1 plan coincidentally Formula One is coming to Melbourne this this week in fact they're probably here already setting up for the Australian Grand Prix so let's pick the f1 plan and it just tells you it's shared infrastructure one gigabyte of memory we get sixty minutes they compute for free so that means that's how the charging model works it works on compute minutes we get an hour for free everyday source absolutely no way we're going to use more than that for this tutorial so let's apply that clickable key here and we'll just make sure that our chip or placing plan has been selected and we know click create and as you will go off and create that resource for us and you'll get a little notification up here when it's done legal deployment and progress now well that's deploying there's another way you can actually create this resource so we went through a manual step by step process we only have to do that once by the way so once this resource is created that says it's created and our as your DevOps pipeline can push to you know multiple times it doesn't get me created we don't have to intervene manually to recreate it so it's done once however you can take it a step further and actually script up the creation of that resource that we did there so rather than as manually going into the portal and creating it you can script it and I believe you can even trigger those scripting from as your DevOps so you potentially have a situation where it's totally automated and you're actually setting up the infrastructure that you need as well as part of your build process so I've not done that on this occasion but that is something I do in a later video or something you can do as a bit form work yourself if you are interested in that Google arm templates as your resource manager template so they're basically JSON files that be that dictate how your resources get treated so you can bake that and as part of your build process so back over here I think that has finished let's look in the notification yes deployment was successful let's go to the resource and it has started so you can stop it if you want you can obviously delete it at some point it's even got a URL here that will take you to the resource live on the Internet so there you go your app service is up and running and so within a couple of minutes you have provisioned an API app on Azure that is accessible anywhere in the world so it's really really powerful it's really really cool so we can now use this resource as our endpoint for our release pipeline okay so our resource is created on Azure let's jump back over to Azure DevOps and create our release pipelines or under pipelines we click releases new pipe plane and we'll pop up with this and a number of templates that we can use coincidentally and the first template that's popped up as your app their service deployment is exactly the one we want so let's click apply on that and it comes up with this concept of a stage which you can see in this kind of we will see it more clearly in a minute in this designer at the back there but we'll give the stage a name and call anything you like but try and call it something meaningful so we'll call this the fly to fraud because you okay now I find this interface a little bit clunky in order to get to this box we have to close this down but in my mind that's kind of almost as if you're canceling over but we're not really so click here and that brings us back to the stage I don't really like that and you can see here that there's a problem with this particular steam stage with one of the jobs and one of the tasks within it so let's drill into that now what's asking for basically isn't as your subscription so we're saying we want to deploy it as you're seeing okay cool we're now at a stage clearly as your DevOps and as you are ordering the name are completely separate entities in fact using the same Microsoft account for both and but it's not they've not joined those together yet so anyway I you select your subscription I already have my menu and it still asked me to authorize so I already had that in there if you don't have it in the drop-down you will have to yeah basically provide you as your subscription by by signing in so I still have to authorize you just get the Microsoft sign in so I'll just type in my credentials here passwords which is already saved cool this just means okay goes away and this should authorize okay assuming I've put password incorrectly okay that looks okay and then it's asking for the app type now we created an API app on as you're not a web app so their Eagles like API app and then it's asking us for the app service name so what should happen because we've selected a subscription and have told that what app type it is it should go off to Oval as you just as your subscription and find all the API apps that we have configured so let's click on the drop down and there you go if you remember when we created it we called it where's Jackson legal so that's all good and all those arrows that were pinging up have been resolved so let's quickly save asses for a safe folder I just use the default one at the stage okay so let's go back to the release pipeline so we have a new release pipeline I wanted that to take me back to the designer so that's a little bit strange I want to us edit this one yeah okay that's a bit clunky so this is the stage that we just created what we then need to do is add an artifact though the artifact is the output of our build pipeline so if you just do add an artifact what do we want to add we want to add what project well it's in the same project that this Pete Lane is being created in and then we look for the source of that build pipeline and here we are it's the the build pipeline that we recreated now it's asking for the option do we want so we want the latest so every time we create a new build we want to publish that build-out - as you are and then it's just asking for a source alias I think that all looks good let's click Add and then the last thing we want to do is this little continuous deployment trigger so as I mentioned at the start we have continuous integration cool and then you have either continuous deployment or continuous delivery no continuous delivery is taking us up to the point where we can publish our artifact manually a push of a button continuous deployment is we are what we're going to do now where we actually trigger the deployment automatic way all the way through so we want to activate that here and by default it's turned off okay so here you go continuous deployment trigger we want to enable that not sure that error is I've seen it before I just tend to ignore it it doesn't seem to have any impact so let's click Save you can put a comment and I think pasta because you're seeing you what you're going to you've enabled automatic or continuous deployment to Oates's your immune if you wanted a comment and there so we're done so that is effectively our release pipeline setup so we have an artifact that's of our build pipeline we've set up our continuous deployment trigger and we only have one stage which is basically pushing that deployment out to zero and we've specified the end point and the usual subscription and the API app that we want so if all has been done correctly we are now ready to push our build out - as your production and what we're going to do is we're going to trigger a build on our desktop and hopefully propagate all the way out to production Azure so just to labor the point let's go back to our app service let's just put in API values just to prove our point this should return nothing so we're not actually deployed on app onto zeros as you're yet the app is running but there's nothing there so I'm just showing you there is nothing there so back over in our API application we're going to push a build up to github as it just said and so what we're gonna do is we're going to trigger or change so I change these values in one of these action results let's change it to something like darknet as our first value and look as the other I lied I said I wasn't going to mention my blog again I lied that's what my blog is called dotnet playbook on in fact that's not it's not porn so we've changed one file that's doing its status yep with our controllers change so we'll get add to add that for commit status again it's ready to be committed get commit message and also changed its own values okay now we do get I think this should be our last get push origin origin master fingers are getting tired to trigger our build pipeline which will then trigger our release pipeline it should push our API in terms of production as exciting times I can see you're clenching you're clenching your teeth in your fists and everything else that can get clenched so let's go over to our dual pipeline first and we should see that popping in here at some point and we'll keep an eye on that there we go when you build so we'll let that do what needs to do do what do what it needs to do okay so our build pipeline has completed so you can see here my release pipeline is actually running and it's seeing it's deploying to deploy to plotters you're in progress which is the name of the stage that we specified now I have fun with this unlike with the build pipeline you can kind of watch it and then it will turn green I have fund worth the release pipeline you cannot have to navigate away from the page possibly to see whether you know this is completed I'm sure that will change that in time or maybe it's just me I don't know but I found it seem to be taking an awfully long time to deploy an end when I browsed the way in refreshed its it's been deployed so I'm not sure if they're if they've got that down anyway this is exciting times it's our first deploy to Azure and hopefully it will succeed it's looking good so far so let's keep our fingers crossed let's just navigate away navigate back yeah there you go so it had deployed it just needed the page to the flesh so you can see here deployed to plod Azure has succeeded I guess we can click on that and you can see yeah the step has succeeded they are she's looking pretty good so the final test then is to go back to live as your and if you remember you know trying to resolve this did not work so let's try again not only did that work but actually is using the new values that we had put in here so what we have proven is that we can write our code down on our desktop you can publish it to get hub we can run it through a release pipeline a build pipeline sorry build pipeline first build it test that package it ready for deploy and then push it straight through into the production Azure environment a little bit you I find that technology incredibly impressive and I really just you know straight scratch the softness and use the relatively simple example and joined the dots for you so I'm hoping personally to take this and extend that out and play a lot more with this urine the capabilities of this particular product and I hope that you also found the video useful as you in your first steps enters your DevOps and CI CD generally so again thank you so much for joining me and making it all the way through to the end of the video if you liked the video please give it a like and if you haven't done already please subscribe to the channel and remember click the little notification icon and you'll get email a updates when I post up new content until then thanks very much stay well take care I'll see you next time
Info
Channel: Les Jackson
Views: 133,697
Rating: undefined out of 5
Keywords: dotnetplaybook, binarythistle, les jackson, .net, .net core, rest api, azure, azure devops, build, release, ci/cd, xunit, git, github, azure-pipelines.yml, test, apiapp, c#, step by step, tutorial, playbook
Id: SOtC1VLZKm4
Channel Id: undefined
Length: 80min 26sec (4826 seconds)
Published: Sat Mar 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.