YAML RELEASES In AZURE DEVOPS PIPELINE | Configure Build and Release in YML file

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
earlier last year azure pipelines yaml continuous deployment features were announced this allows configuring release pipelines as part of the yml file which was earlier limited to the build pipelines alone prior to this the release pipelines could only be configured using the visual user interface editor this is now referred to as classic releases with the aml releases the pipeline lives in the yml file along in the source code repository this allows versioning of the build and release pipeline and it grows along with the application in this video we will learn about yaml releases its high level structure and use that to deploy a web application to azure if you're new here my name is rahul and welcome to this channel i talk a lot about dotnet azure and devops in this channel so if this is of interest please make sure you hit the subscribe button without much delay let's head off to my azure devops account i have a new repository setup here with the name yaml releases there is already a source folder and also a deploy folder pushed up to this repository the source folder contains an asp.net core react single page application template i had spoken about this template and showed you how to setup a build deploy pipeline a while earlier in the videos linked here under the deploy folder we have an arm template file the webapp.json file which creates an app service plan and also an azure web app under that this is used to create the azure resources when we set up the release pipeline we also have a web app dot parameters file which takes in an app service plan name and also a web app name we will replace this in the release pipeline to the appropriate name for the stages or the environment that it's getting deployed to here you can notice that it starts with a hash and also end with a hash we will use this pattern to do the variable replacement which we will see in a moment later if you are new to arm template and how to create this file i have a separate video walking through these entire steps to create a file very similar to this the video is linked here and also in the description below before we head off to create the release in a yaml file let's see how the classic releases used to look like for this particular application so if you come under pipelines and navigate to releases i have already created a release for this particular project you can find that under yaml releases so if i click edit you can see the template for this particular release here i have this bound to the artifact to a build pipeline and also we have a dev and a test stage inside the dev i have three jobs which is one replacing a token for the web parameters json file which we saw earlier and also creating the arm template deployment based on that arm template file once that's done we deploy this to the azure web app service the build pipeline that is targeted here is also available as part of this project so if i go into pipelines i can see the yaml releases build only pipeline if i click into that i can click edit and there is the yml file that's living as part of the same repository you can see in here it builds the application using dotnet 5 using the dotnet publish command and it publishes the artifacts and publishes the arm artifact files as well this file is available as part of the repository which is all public and you can go through this if you wish coming back to releases you can see this is already released into the dev environment so if i go into my azure subscription you can see there is one which is the yaml releases classic dev now if i go to this application i can see this starter template from the dotnet core react single page application so let's see how we can now move this into a yaml release pipeline so let's navigate back to the source code let's go to the repository and files so the build only pipeline is living inside this yml file so let's take a copy of all this because we'll be using exactly the same to set up the build pipeline it's only the release pipelines that we will be moving under this file again so let's take a copy come back to pipelines and go to pipelines again to create a new pipeline you can click the new pipeline up here so let's select azure reposts get let's choose the appropriate repository in this case it's the aml releases so let's choose that in configure your pipeline we can start with an empty pipeline so we can say start a pipeline and that creates a default set of pipelines let's remove all this and replace it with the contents that we copied so now we have a build pipeline to build the whole project let's modify this to start adding the release pipeline as well let's look at a high level overview on how the yaml release pipelines are structured so here we have a trigger which then starts off a pipeline which has multiple stages as you can see there is stage another stage and another stage inside each of these stages which is now associated with an agent it has a list of jobs so these jobs then has a set of steps under them so these are the steps that actually does the work like building the application or copying files or publishing to an azure resource etc so let's see how we can set this up now if we come back to the new file that we just created you can see that there is no stages mentioned here so the stages is optional to keep this backward compatible because the original build pipeline didn't have a concept of stages so now we can move this whole pipeline under a stage which is the build stage so let's start doing that the trigger is still common so let's leave that and start adding the stages after that so let's copy down everything after the trigger let's remove it for a second and start adding stages so if you start typing in stages it will provide the intellisense so you can select stages from here once there you can create a new stage which is our build stage so let's give this a name build now under a stage we saw it had jobs so let's go at jobs under this stage build so we can use jobs and create jobs for that so let's create a first job which is build web app under the job we can paste back in the contents that we removed earlier for the build pipeline so let's go to the next line and paste back in all those contents since this is not aligned properly let's select the entire contents and then use tab to align this under the job so pressing tab this is going to move that under to the job now i have this lined up right under the job which is now good enough for us so let's remove this extra line if you want and now you can collapse this whole stage as one stage which is the build this is now a valid pipeline again with stages added to that let's start adding a new stage under the stage build so let's go to the last line make sure we have the cursor in the right position use dash and press stage again in this case we need to deploy to the dev environment so let's name this deploy dev we can also add in a display name if you want and provide a valid name for the stage so let's say deploy to dev so let's make sure we have a line in between that so if you scroll up you can now collapse this build stage so that you can start seeing the entire deploy dev stage under the stage we saw earlier we need to add jobs and each of these jobs will contain the agent that this needs to be run on so let's start adding jobs under this so we can say jobs and start defining what kind of a job this is since this is a deployment job we can use the dash deployment instead of the dash job that we used earlier for the build pipeline so let's choose deployment a deployment job is a specific type of job which is required for deployment so it has a collection of steps which are sequentially run against an environment now the benefits of a deployment job is that it provides deployment history and also apply a deployment strategy which we will see in a moment later so let's go back and start adding the pool for this particular deployment now since the job requires an agent we can come back to the stage pipeline and use the same agent that we used inside the build since this is a.net core application i can use a linux based image as well so let's collab this under deployment let's paste the pool which is now a vm image of ubuntu latest now earlier we saw that a deployment job can specify an environment so let's specify an environment and this is going to be the dev environment if this doesn't exist already it will be automatically created we will see about environments later in this video so let's keep going and start adding the strategy that we saw earlier for deployment this is defined under the strategy keyword so let's use strategy and then we can pick one of the available strategies if we go back to this url we can see their strategies that's available as part of the yaml release pipeline so we have run one's deployment strategy we also have a rolling deployment strategy and a canary deployment strategy each of these has separate functionalities we will be using the run once deployment strategy run once is a simple deployment strategy where all the lifecycle hooks will be executed once so what are lifecycle hooks so if you scroll above you can see that there are different lifecycle hooks available as part of a strategy like pre-deploy deploy route traffic etc you can read this documentation to understand all the details for now in this video we will only be using deploy because that's all we are looking to do so if we come back to the pipeline we can start defining the strategy so if you go under strategy we get an option to choose three of the options that we just saw so let's use run once and specify the deploy hook you can also see the other hooks that's available here and you can use that to do whatever you require so let's choose deploy and specify steps under that this is where we will start adding deployment steps in this pipeline earlier in the classic releases we saw three steps that's required first we had to replace the arm template parameters file then we had to create the arm template deployment and then the azure app deployment so let's do exactly the same in here to add a new step the easiest is use the show assistant which is on the right up here clicking that is going to pop out a menu where you can start adding tasks so let's first search for the replace token task this is a task available from the marketplace so you might have to add it before you can start using it since i have it already added let's select that now this is going to ask me the root directory where this needs to look at so let's specify the drop arm folder where these templates are getting packaged into so we can use the dollar pipeline.workspace variable which is available by default to refer into the workspace directory under that we use the drop arm directory so let's select that we want to target only the parameters file so let's explicitly specify the name of the webapp.parameters.json after that we can leave all of this as default under advanced we can use the prefix that's used so earlier when we saw the file we saw that it was prefixed with a just a hash so let's remove the extra braces and that should then replace these parameters so everything else looks good let's make sure we have the cursor under the appropriate position remove the extra dash and then click add so this is going to add that task right under the steps so we have the replace token task now added next we need the arm template deployment task so let's again press go to a new line under the steps and then search for the arm template deployment so we can add that task and start specifying the parameters for that so let's choose a service connection in this case i'll use a visual studio professional connection that i already have and the subscription that's under that let's give in a resource name now this is automatically showing the resources that's available as part of my subscription but let's add in a new one so let's say yaml releases dash dev and say use that particular name in the location let's choose australia since i am right now there for the template file let's copy the drop arm folder that we used earlier and also make sure that we give the web app dot json file name for the parameters file we can specify the same name with the dot parameters so we have everything specified here the deployment mode is incremental so let's make sure the cursor is again in the right position and then click add now this is going to add the next task that's required for the arm template deployment up here in the root directory there is an extra codes so let's make sure to remove that now that looks good now to add the last task we need to add an azure web app deployment so let's make sure that the cursor is in the right position and then again search for azure web app deployment which is the azure app service deploy task so let's select that choose the same subscription so i have the visual studio professional it is a web app on windows i can give an app service name which now comes from the variables earlier we saw in the source code that this parameter file has a name arm underscore web app so let's use the exact same name as our web application name to use that as a variable we can specify dollar and specify the web app parameter name for the package or folder we can again use the dollar pipeline dot workspace and pick up the zip folder under that particular workspace so this is going to have the web app which is deployed as a zip in the build pipeline so if you scroll up you can see in the build stage that we had published the web artifact which is a zip file inside here this is publishing it as a zip file so let's collapse that make sure we have it in the right position and click add so this is added the last step which is publishing the web application now that we have defined the stage let's collapse this to make sure everything is aligned properly we now need to specify the variables that's required for the arm template and also this step that we use the arm underscore web app now to define variables we can do that right above the jobs so if we go under the display name we have the variables option in here we can specify a group that's a variable so let's use that and specify dash group we can give in a name so let's choose yaml releases dash dev since this is the dev environment we will specify this group a moment later before that let's save this file let's create a new branch named azure pipelines and start a pull request as well if you are new to pull request workflow you can check out the video linked here so let's click save so that has saved this file now to create the variable groups let's go under library on the left on the menu so under the library you can create a new variable group so let's make sure we have the name as the same so let's say yaml releases dash dev under this we need two variables one is the web app and the app server's plan name so let's copy this create a new variable which is the app service plan let's call this yaml releases dash dev and we also need the other one which is the arm web app name so let's use that and given the same name so let's say yaml releases dash dev so now we have the variables created if you want you can also link these variables from azure keyword which i have shown you in another video so let's click save so now we have the yaml releases dev created up here which is also used in the pipeline so if you select all we can see the pipeline that we just created so select yaml releases and click run pipeline now by default this is going to look into the master branch but we had that saved in azure pipelines because that is the pull request branch that we created so let's select that and click run now this has started the whole pipeline process and you can see there are two stages that's coming down here so one is the build stage and the other one is the deploy to dev stage so if we click into the build stage you can see all the steps under that now you can see it's using the dotnet step building the application and then it will publish the artifact once this is completed it will automatically move into the deployment stage so let's wait for that to happen now the build stage is completed and you can see there are two published artifacts so if we click that we can see the drop file which is the web app which is a zip that we have used in the releases pipeline and also the drop arm folder which has the two template files so this is what we referred using the dollar pipeline dot workspace variable if we go back to the pipeline you can see that the deployed to dev step has started now this is downloading the artifact it's replacing the tokens it says two of the tokens are replaced looking at those parameters file now this is running the arm template deployment file so once that's run it will move on to the web application deploy if we were to go into the azure portal we can go under resource groups and we can see that the resource group is already appearing up here so if you select into that and go into deployments you can see the arm template deployment that's happening so this now says succeeded which means it is successful so you can also see the deployment details and you can see it created a site and also the server forms up here so you can see the full details of the arm template deployment under here if you go back to the pipelines this whole step should be now successful and now it's deploying the web application from the zip file so let's wait for that to complete before we run the website the deployment is successful and it's successfully deployed to the dev resource so let's switch back to the azure portal go back into yaml releases dev go to overview and select the web application that's created so this has the same name that we gave inside the variable group because that was replaced using the replace tokens tasks so let's navigate to this url and you can see the same react application set up and running successfully so let's go back into the azure devops account and under environments we can now see the dev environment this was automatically created when the release was created so if you navigate into that you can see the successful deployment that has happened under this you can further drill down into here and see what all the changes are and also the associated work items if there are any so if you go back into jobs you can see a summary of all the jobs that has happened an environment is a collection of resource that can be targeted by deployments we saw in the pipeline how we targeted the dev environment using the environment keyword so the advantage of using an environment is that it has all the deployment history you can trace the commits and work items just like we saw now and also you can allow permissions to deploy to this particular environment so let's see that in action navigating back to environments let's go create a new environment and name this test so let's say for this particular environment let's choose resource none because we don't use kubernetes or any virtual machines so let's say create which creates the test environment now let's say deploying to the dev environment needs to automatically happen anytime a build is happening but to deploy to test we need certain approvals maybe that needs to be approved from the dev team that everything is working fine on the development environment so to create these approvals let's go to the right dot dot and add the approvals and checks from here you can add various approval options to see everything you can click see all so you can see it has an approval which is basically by a user or a group you can set branch controls you can send the time of deployment etc so let's check approvals and click next in here let's add myself you can also specify if the approvers can approve their own build runs and also the timeout in days or hours and minutes so basically this build will get timed out after 30 days you can increase that if that's what you want so let's click create and this is automatically created an approval you can also add user groups if you have them in azure devops so now to start using test let's go back to the release pipeline now if we go into the pipelines you can start editing it from the yaml releases so let's select this and select edit to add a deployment to test let's copy this whole stage so let's make sure to select and copy the whole deployment to dev stage and then paste that below that so let's make sure i have it in the correct position and paste all the contents now i have the deploy to dev and let's start renaming this as deploy test so let's rename all the dev to test now for this environment since i have already created test i can use that and it will not be automatically created since it exists everything else remains the same now for the resource group name we can change this to test as well and everything else looks fine so let's look at the variable names now that has yaml releases test so we'll need to create a new group with the same name so let's save this again commit it to the branch so let's say adding test environment and click save let's go under library and clone this variable group so clicking clone is going to create an exact copy of that so let's name this test and also make sure to replace these to be test so when it automatically creates the resources it will use this name let's click save go back to pipelines and run this pipeline again make sure to choose the azure pipelines we have not merged this pull request yet so it's still on that branch so let's click run now you can see that the commit is adding test environment and also it has now a third stage appearing up down below so now it has a deploy to dev and a deploy to test and the build which is building currently the build is successful so it is automatically started the deploy to dev like we wanted once the deploy to dev is completed you can see that this is now waiting on deploy to test this is because of the approval that we had added if you navigate back to the pipelines you can see that here also there is a wait symbol if you click on that it shows a message one approval needs your review before this can be run so if let's click review and it says these approvers must approve so since my name is already there and i'm logged in with the same account i can reject or approve this particular release so let's say tested in dev and select approve now that's going to trigger off the deploy to test stage if we go back we can see that now this is started to continue execution now that will wait for the timeout days that we had specified after that this will become invalid so you can pick and choose based on your team's workflow how and what approvals you need to set for these pipelines and the environments that's there so let's wait for this to complete if you go into the test you can see it has already replaced the tokens and it has two tokens replaced and it's now currently using the arm template deployment so if we go into the resource groups and refresh this you should be start seeing yaml releases test so let's navigate into that and the deployments will again show you the history of the deployment once that's complete we should be able to see the web app in here so let's wait for this pipeline to complete the pipeline is successful so let's navigate back into the azure resources refresh this and we can see the web app up here so let's navigate to that and we can see the asp.net react template again so now the whole release to the test environment is also successful so let's go back to the pipelines and under environments we can now see that dev and test both has a deployment against it if you navigate into the dev environment you can see there are two runs because the initial run and the next one that we created for the test if you navigate into the test you can see only one which is the latest deployment that we just did now if your environment has multiple applications let's say an azure web app a windows service an azure function etc you can target all of that to the same environment so you can see all the different deployments that's happening for your application as a whole inside of here under the pipelines you can also see a good summary of the releases that has happened and the different stages that has run i hope this helps you to understand more about yaml releases how it's structured and also how to create one of your own based on your application you can use different tasks in the release steps and build and deploy your application now as we saw the releases now belongs to your yml file and lives along with the source code repository so it grows and upgrades along with your source code try migrating some of your smaller projects into this yaml release pipeline and see how that goes if you like this video please hit the like button and also feel free to drop in comments or questions below don't forget to hit the subscribe button to be notified in the future of similar such videos thank you and see you soon
Info
Channel: Rahul Nath
Views: 12,778
Rating: 4.9464884 out of 5
Keywords: yaml release pipeline azure devops, yaml release pipeline, azure devops yaml pipeline, azure devops yaml, azure devops yaml release pipeline, azure devops yaml release trigger, yml release, azure devops release pipeline, yaml pipeline variable groups, azure devops environments, azure devops yaml release web app
Id: F93dKycIqEM
Channel Id: undefined
Length: 27min 57sec (1677 seconds)
Published: Thu Jan 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.