Templates in Azure DevOps Yaml Pipelines

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Salam alaikum and this video will learn how to use templates and agile devops yeah more pipelines in order to reuse and share the CI CD templates to understand why this tool is really useful let's use the use cases where we want to deploy the application multiple times or we want to deploy into multiple environments like dev tests and prod and those cases will see that an our CI CD pipelines will see some blocks of the code that are repeated again and again so the idea here would be to refactor boost blocks of the code that are repetitive and to put them inside a file that we call it a template then from our main CI CD pipeline we can call that template when we want to repeat it so at to understand how that works show me here to show you a demo on Azure DevOps so here I have the demo and all the scripts for for this lab available in this github repository so you can go to check it out and here I have actually two demos we'll start first by seeing a sample pipeline that's what I have here and this sample folder so if I switch to my vs code and this folder I have two pipelines so first is the main pipeline that will be triggered once when we push on the master branch and then contains some steps and here for these steps not how we are using those templates the sample template the step dot UML is actually the second file that I have here and this one which is my template this contains a list of steps for here I have only one step that will just echo hello from llaman templates and also develops pipelines and I'm repeating the same template three times here it means in my pipeline I'll go to show that mr. three times so let's see how we can create the pipeline that uses templates first so here I'm inside a DevOps I have created a new project and here I have gone to the pipeline's than the pipeline's here I have already - pi is created before but it goes through you how you can create a new pipeline to use the amel configurations so here I'll choose where from which I from where I can get my armor configuration files and here it's my github account so I select github with Yammer and then for the select here I go to select the repository that I'm using today for the demo after that I can either choose one of these existing yeah pipelines or templates or what I can also do is that I can use an existing pipeline that is available on my github repository so because they have created that before so here on from my master branch I go to select the sample of your pipelines so I select this one continue and then other devops will get that file will read it and it will show it to me right here so from here I can see my three steps describe it in another yeah more pipeline so here I put actually the path through my ml pipeline and here because I'm inside this sample pipeline inside the folder sample pipeline so I don't need to add a sample pipeline into its path because already the main pipeline is inside that folder so from here if I go to run this pipeline right here in a second that will be Hewitt and if I click on it I see that here it's triggered and it will show it or it will run the step describe it inside the template three times and here we can see the message hello from yama templates great so this was a sample pipeline but in some other cases we want to pass some parameters and to that template because maybe you want to change the application name or the database login and password and some other parameters so how can we take those use cases so in here I'll show you my second demo which will show you how we can pass parameters and two pipelines so and this and this file here in this pipeline which is by the way also available on the github repository so that's the file that is in here with the free templates and this pipeline I have a list of variables and those variables will be needed by the different templates so here I'm using first template for creating the terraform backend so in this case I'm simulating that I want to deploy my own first lecture using terraform so first thing to do is to create the terraform storage account for terraform in order to store the terraform state so for that i'm using a dedicated template for that so that i can reuse that template and from different from multiple projects even if those projects even my template lives and another git repository i can actually reference it from other repositories so that's a nice way to share those templates so in this first template i go to pass some parameters so i'll go to take the values from the variables section here and into that template which I can show right here create your own backyard I'll take those parameters from here so those will be overrated by this list of parameters then I go to take those parameters and use them inside my template not here I'm creating a list of stages with jobs and steps on and I'm used reusing those pass it parameters in order to create the storage account and the TF state file so the template here what it's doing is that it way it is inserting the content of that file into this pipeline and then and Here I am using a second template which will run the different or which will be used in order to run into one single environment because here in this case I want actually to deploy into my dev test and the prod environment and for each environment I want to pass some different parameters so for my dev environment I want to pass the name dev for this environment along with those different values and I'm using the template terraform stages let's see the code for that template so here what I'm doing is that I'm trying to deploy the terraform and for a structure so first of all I'm installing the offer as first task then I'm running the different terraform commands terraform init plan and apply and here I'm taken also those configure those variables in order to use them inside this pipeline so in here I'm using that same template three times in order to deploy to my dev test and production environment along with different variable values right here so that makes it really easy to share and reuse the different templates if I don't use the templates here it means that I will write this thing the code for that template three times so that this main template would have hundreds of lines of code and if I want to make change into the template then that change will be reflected in all my environments immediately so this template will deploy terraform template which is available and the code repository here so that half the main dot EF which we'll just go to deploy a resource group with a name passes into it and then the template will run the different terraform commands in order to deploy it let's see here sample for running those those pipelines so from here you can see first I start running the first template which will create the terraform back and then the one that will deploy into dev tests and then deploy into production and you see that here some of those stages will run in parallel that's because in our pipeline we have created or we have use it dependencies in order to say that the production on for example will depend on the dev and test environment we run only after they finish running so I'm using the depends on here which will be passed it and to the create terraform backend template so it will get this value for depends on and then it will use it in my different stages so that an azure on my other subscription that will create three state files and to my storage account one for dev prod and test and that will deploy also in the three resource groups which are dev broad and test so templates are a great way to share and reuse code across different projects and to be used across multiple teams and our organization so what I see organizations or enterprises doing is that I create like a base git repository in which they put their templates and those templates will be reused by the different product teams in order to agree on using some standards on tools on those templates so to learn more about templates and about some of the other features available with templates and how you can apply it into your other DevOps I'll leave you here with this link right here that have more details and more features available and from here and they would also invite you to check more my videos on YouTube where I post about anything DevOps kubernetes and Microsoft Azure I hope you have liked it this video thank you
Info
Channel: Houssem Dellai
Views: 24,021
Rating: undefined out of 5
Keywords: kubernetes, devops, azure devops, azure, aks, k8s, docker, container, ci/cd, continuous integration, continuous deployment
Id: US_e31hZiWk
Channel Id: undefined
Length: 10min 48sec (648 seconds)
Published: Sun Jun 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.