Azure DevOps pipeline: Create a .NET build pipeline (CI/CD YAML tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
after two and a half minutes our job is complete all tasks have run successfully we can see all our tests have passed and it's produced our artifact in agile pipelines an azure devops pipeline is essential if you want to set up ci cd in azure before you can release your dotnet application you need to set up a build pipeline which is what we'll have a look at in this video now if you're new to azure check out our video what is azure devops at youtube.com roundthecode for more asp.net core tutorials visit roundthecode.com and follow us on linkedin at roundthecode.com linkedin check out our.net 6 course on dependency injection a must for software developers visit roundthecode.com courses this is the project that we're going to be using to create our build pipeline it's an asp.net core web api built in dot net six if we give it a run it loads up a swagger documentation and we can see we've got one endpoint here if we go ahead and try that out it gives us a response of true it also has unit tests as well so we want to make sure that they're all passing we can see that they're all passing so this project is now ready for azure devops we're in our azure devops project and we're going to create a pipeline we're going to select where the code is our repos in github so we're going to select that we're going to select the appropriate repo which is the azure test project and this gives you some templates to configure your yaml file we're going to go with the bare minimum and select start a pipeline now we're going to go ahead and delete all the contents in it and we're just going to go ahead and save it this will now commit it to our repo with our build pipeline set up we can go ahead and edit it the first thing we want to do is to set a trigger triggers can be used for continuous integration so when we make a commit to a particular branch it can go ahead and run our build pipeline to do that we use the trigger key we select branches select include and include the branch's name which in this instance is the main branch now every time we make a save to our yaml file it commits it to our repo at the moment this would trigger off a build pipeline every time we saved it so we want to turn this off and all we need to do is we need to add none underneath the trigger key microsoft has a number of virtual machines that we can use to build our pipeline as we're using a application we can use the windows latest so to do that we add the pull key we select vm image as the key and the value for that is windows latest next we're going to set some variables variables are good because we can use the same values in different tasks and we're going to be using the net core cli for a number of tasks within this to do this we set the variables key and we're going to select two variables we're going to select the build platform we're going to select that to any cpu and build configuration to release now we can go ahead and set up some tasks before we set up tasks i want to add some extra variables i want to add one for the solution so i'm going to name that round the code the azure test project.sln and i also want to do the same for the web project i'm going to set it as project i'm going to change the extension name to csproj now we can add some tasks and we need to add that within the steps key the first task we want to do is we want to install nuget onto our agent so we do that by selecting the new get tool installer here we need to there's there's a few advanced options here but we're not going to set them as we don't need to let's add that into our yaml file we don't need this inputs what i like to do is i like to add a name and a display name to each task now the name for this is going to be new get tool installer and the display name is going to be the same but with spaces now the difference between the two is the name acts as an id so you can't have spaces in it and the display name is more human readable our next step is to restore any new get packages so i'm going to do a search for nougat and select the new get task here we've got the restore here's the command we've got the sln file so it's looking for any slm file within the repo i like to be a bit more specific and we select the solution variable here so to reference that we can wrap it around a dollar and brackets and do that and everything else should be fine so we can add that in at this stage we could build our application to see if it's running properly but we've also got unit tests that we want to pass and it's going to have to build properly in order to run the tests so i'm going to go ahead and select netcom we're going to run the tests at this stage i'm going to select the command as test the path to project is going to be the solution once again we set it as a variable so we can reference it with the dollar solution wrapped in brackets the arguments we've also set a build configuration variable and we're going to reference it at this stage so we're going to build it in release mode and we will just reference it with the build configuration and we want to publish test results and code coverage let's go ahead and add that in assuming our tests have run fine we want to go ahead and publish it we're going to use the net core task here we're going to select publish now we're going to unselect publish web projects if that's selected it will find the first web project within your solution that's fine if you've only got one but i want to be a bit more specific just in case we were to add different web projects at a later date so i'm going to go ahead and untick that and the path to project we're going to reference the cs proj file this time so if we go back up here to our variables we can see that we've referenced the project in our variable project so we're going to add that in here now for the arguments once again we're going to use the configuration parameter we also want to add an output parameter and we're going to set this to the build.artifact staging directory what this will do is it will output our publish files to the artifact staging directory what will happen in a minute is we will publish the build artifacts up to azure pipelines which can be used in a release and we're going to untick the sip publish projects and we're going to go ahead and add that task finally i want to go ahead and publish the build artifacts to azure pipelines so we'll do a search for publish build artifacts we're going to give it a different name of azure test project you can see our path to publish is the build.artifact staging directory variable and the location is azure pipelines let's go ahead and add that now i want to go ahead and add the name and display name to each of these tasks so we know what each one is doing so for this we're going to set that to new get restore i'm going to set that the name the display name as restore packages do the same for the tests we'll give it a name of tests and display name of run tests same for publish call it publish and once again for publishing the build artifacts let's go ahead and save that that will commit our yaml file to our repo now we can go ahead and run uphill pipeline to see if it's going to run or not we can run our build pipeline by clicking on the run button up here select the branch and tag and commit we're going to leave that as it is going to go ahead and run it that's now running our build pipeline it's going to take a few moments so we'll come back when it's finished after two and a half minutes our job is complete all tasks have run successfully we can see all our tests have passed and it's produced our artifact in agile pipelines if we have a look at the artifacts and have a look at the published files we can see we've got all our published files from our application this is now ready for release let us know in the youtube comments what is the one thing you like about azure pipelines has it sped up your build time or maybe you can do more releases also check out our video series death to azure where we go ahead and publish an application to azure you can check that out at youtube.com forward slash around the code and thanks very much for watching and hit a like on the video
Info
Channel: Round The Code
Views: 42,648
Rating: undefined out of 5
Keywords: Azure DevOps Pipeline, Azure DevOps Pipeline .NET, Azure DevOps Pipeline .NET Core, Azure DevOps Pipeline ASP.NET Core, Azure DevOps YAML, Azure Pipelines YAML, Azure Pipelines tutorial, Azure Pipelines CI/CD, Azure Pipelines ASP.NET Core, Azure DevOps Pipeline Tutorial, Azure DevOps Pipeline Demo, Azure DevOps Pipeline Setup, Azure Pipelines demo, Azure Artifacts, Azure DevOps Build Pipeline, Azure DevOps Build Pipeline tutorial, Azure DevOps CI/CD Pipeline tutorial
Id: EUszBUnCKlo
Channel Id: undefined
Length: 10min 2sec (602 seconds)
Published: Sat Jun 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.