How to configure self-hosted Linux Agent in Azure DevOps | How to setup Azure Pipeline Agents

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back in this video we are going to learn how to set up self-hosted Linux agent in Azure devops so let's try to understand more about agents so Microsoft provides two kind of Agents so one is called Microsoft hosted agent which is available from Microsoft itself so whenever you perform build in Azure build pipeline those options will be available for you so all these are like you know all these agents are VM running in Azure Cloud so you can use any kind of VM it could be Ubuntu it could be Mac OS it could be windows so you can use all kind of Agents so they're all provided by Microsoft so you don't even have to worry about managing any operating system patches or security patches you don't even have to worry about that everything is provided by Microsoft then there are other set of agent Called self-hosted Agent so which is nothing but you can create a VM you know you can set up up a VM on your local machine and then you can consider or you can configure that as a build agent or you can also set up a VM in Azure Cloud you can also configure that as a build agent so what is Advantage so you have more control over over the VM right so you can manage all the updates and whatnot okay so depending on the use case either you can go for a Microsoft hosted agent or you can go for self-hosted agent okay but this particular video we are going to talk about how to set up self-hosted agent okay so what we are going to do is we are going to provision a VM in Azure cloud and then we are going to configure agent on that machine okay and then our Azure devops pipeline will use that agent to perform either build or deployment okay so that's exactly what we are going to do in this video awesome so let's quickly go the prerequisites yes we need to have Microsoft account setup because we are going to create a VM in Azure Cloud so you also need to have Azure account and subscription setup so I'm already logged in here and then this is my this is my Azure devops uh you know dashboard and then this is my Azure portal uh so we are going to create a VM and then we also need to create personal access token as well in Azure devops so we will cover everything one by one okay so how do you configure self-hosted build agent right in in Azure devops it's very simple so go to your project dashboard so let me click on a project dashboard okay so this is my organization this is a project so go under project settings and then if you go to agent pools so as you can see here so these are all various pools available right so Azure pipelines and then default these two are like you know they always comes out of the box so Azure pipelines are nothing but so these are all like you know agent available from Microsoft right Microsoft hosted agent and then if you look at under default so this is where you can configure your uh custom agents okay self-hosted agents okay you can also create you know agent pool as well and then you can configure agent wherever you want it to okay ah so we wanted to uh create a self-hosted agent so I already have couple of pools but let me create a new pool right so go to add pool so we are going to say self-hosted and let's give some name so I can say my Ubuntu I'm gonna say my Ubuntu Asian pool okay just pull and then you you might want to give access to you know all pipelines okay so I'm going to create a new agent poll and this is a name and we are making as a pool type of self hosted create there you go you see here so now we have created agent pool and then we have to go to agents and click on new agent so this is where you know you can configure your self-hosted agent so as I said you can set up any kind of agent it could be Windows it could be Mac OS it could be Linux or you can also configure agent on your local machine you can also configure agent you know like VM running on a in any Cloud as well you can also do that but what we are actually going to do we are going to set up a Linux agent so we need to follow the instruction over here okay so all you have to do is create this folder and then download the installable and then extract and then you can execute this particular shell script in order to uh you know run the agent okay so that's exactly what we are going to do I have provided all the steps documented here so we already created an agent poll now we have to go ahead and then configure a VM and then set up agent inside and VM so for that what I'm going to do I'm going to go ahead and now provision a Linux VM in Azure Cloud okay so what I'm going to do let's log into Azure portal so click on Virtual machines so let's create a new virtual machine so I am under pay cigo so let's create a Resource Group I'm going to call this as my diversource group let's give some name I'm gonna say my field agent and region so let's select okay so I'm going to go with the default option so let's go with the Ubuntu this is totally fine 64 that's fine uh the size of the VM let's go with the one CPU yeah this is fine one CP with the two gig that should be good enough and then we need to have SSH keys so I'm going to say okay so we need to have SSH keys so this is a key name and this is a username perfect and then we don't have to open any additional port number 22 is fine so let's click on review and create let me download the SSH keys so this will take few seconds to come up so what I'm going to do I'm going to open up my item so that we can connect to the VM and then perform the agent setup so now let's SSH into the VM to copy this link perfect so now we have connected to our VM now we can go ahead and then configure our VM okay so I'm going to first go ahead and then create this folder okay so we created this for follow called my agent and then I am inside the folder perfect now we need to download the installable so this is the installable there you go so we were able to download the installable right and then we have to extract the installable so now we were able to extract the installables as you can see here we see couple of shell script here right so what we have to do we have to perform this command in order to configure the agent okay so if you see here we are going to perform this Command right so let me go ahead and then execute this so now it is asking right um you know you want to accept the agreement and also you have to say yes and then it is asking for the server URL so that is actually nothing but our organization URL so that is that and then it is asking for how it is going to authenticate so let's say Pat or you can enter that's mean personal access token and then it is asking for the token so this is where we have to create personal access token so I have provided that step documented in the prerequisites so you can also click on this particular link this will show you how to create personal access token so for that we have to go to Azure devops dashboard and click on this user settings and click on personal access token and click on new token so this is where we are going to create a new token so let's give a token name so I'm gonna say my token you can leave it like you know when and all you want to expire okay so let let me say 30 days and then let's say custom Define all we have to do is scroll down and then we have to give access to you can click on show all scopes so we are going to click on this one agent polls read and manage so that is access what we have to give and then click on create and then this is going to create the token right so copy the token and then enter the token here so now it is in the process of connecting to the server there you go and then it is asking for the agent pool so if you remember we created a agent pool right let me go there let's go to where we created a agent go to my Ubuntu agents poll and so so we have to provide this agent pool right this is the one what we created correct so so let's enter that and then it is asking for the agent name so you can just enter for this particular name let's enter there you go and then it is asking for the work folder name you can enter so it is going to use the default name perfect so now our agent has been configured uh so you can go here and then click on agents so so it is still showing offline right so that's fine because we have to start the service over there so how do you do that again I have provided all the steps over here so we have to go ahead and then configure the agent as a service so that whenever you restart the VM the service will be always available for you so let's execute this particular actual script and then of course you can also see that here as well right so I'm going to execute this one so let me execute that as let me configure this as a service so there you go now it is configured as a service and then you can go ahead and run the service so let me execute and again you can see here so now then I'm going to go ahead and then execute this cell script so this will configure uh the agent so this is going to bring up the agent there you go so now it says that connect connecting to the server and it is waiting for the job so now if I go back to the pool there you go you see here now our agent is configured right so this is how guys you know this is how you can configure agents now what is the next step now we can go ahead and then perform some build isn't it perfect so our agent is up and running so what is the next step we have to go ahead and then create a pipeline and then we will run the bill using this pipeline okay ah so before we go there I just wanted to talk about what are the steps to uninstall or remove agent from the pool okay so you need to execute these two commands in order to uh you know perform any kind of a cleanup activity okay let's say you want to remove the agent from the pool so these are the commands so you have to perform uninstall and then you have to go ahead and then perform this command to remove the agent from the pool as well perfect um so what we are actually going to do we are going to run some build using this agent I do have a sample Java project configured in GitHub so we are going to create a pipeline pipeline will check out code from this particular you know GitHub repository and then it will perform a build using Maven so for that we have to have Java and Maven installed on the build agent so let's go ahead and then you know take care of that as well so I don't think this has anything installed foreign so let's go ahead and then install Java on the build agent but before that let's just make sure whether this has Java installed yeah it does not have Java installed so let's go ahead and then install Java so I'm going to go ahead and install default jdk okay let's also go ahead and then install Maven as well so let's go ahead and then install Maven as well foreign perfect there you go awesome so now we can use this build agent in order to run any kind of java bills okay so now let's go ahead and then configure a pipeline in Azure devops so I have provided instruction again in my website so this is going to create a simple pipeline which would check out project from GitHub and then it would just you know perform very basic Bill using Maven it's very simple to do that but if you want to learn how to perform slightly complex pipelines and all you know feel free to refer my website I have several uh you know examples in my website like for example uh let me see if I can show you a few Pipelines yeah look at here so I have a lot of good examples like if you want to create a pipeline uh to check out from GitHub and then you know create a Docker image and then deploy into AKs I have a lot of scenarios in my website okay so you feel free to refer my website to learn you know creating different type of pipelines one for Docker image or Docker based application or or even normal web application as well so now let's go ahead and then create this simple pipeline so let me go to the project dashboard and click on pipelines so click on new pipeline and our project is in GitHub so so if you see here it is automatically coming here but uh I have already set up a service connection here let me see if I can quickly show you go to Project settings and then service connections so as you can see here I have already configured you know with the GitHub personal access token okay so um so that's the reason why I was able to check out okay all right so let me go into Pipelines create a new pipeline GitHub so this is the repo name let me copy the repo name and then I can filter okay Enter the report name there you go so that is a project name so select it so now it is actually showing several options right but I want to keep the pipeline very simple because we want to just learn how to you know run the build or using the agent so I'm going to go ahead with this option so as you can see here it is already creating the pipeline code here right so all we have to do is we have to mention the pool name so let me remove this one you can just mention the pool name so that is going to be let me open up another tab so if we go to agent fold so this is the full name what we created right so you just have to mention that over here that's it and we don't have to worry about you know whether like which version to use so we can actually delete this thing and we need to provide where palm.xml resides so in my repository I have this project so this palm.xml file reside inside the my web app folder so I have to provide like this my web app so that's pretty much and then this is the maven goal you can have clean install or package that's totally fine so that's it right that's it uh let's click on save and run save and run so now agent is able to check out the code from GitHub now it started doing Maven build awesome right so the job has done so this is our pipeline right so there you go guys you know we were able to perform the build everything you know using the agent okay so this is for uh you know like running the build using AML file uh but if you want to do it a classic way again very similar right you can click on classic editor you can select the Repository so this is our repository name and continue and let's select a template so we want to just do this one build and test a Java project click on that one okay and yeah so this is where we have to specify right so we are not using Microsoft Hoster we are using our own agent 4 so we have to select this one my Ubuntu agents fold and then let's select the path of palm.xml file so that's it right that's pretty much over there all right and then save and Q there you go you see here the agent pool is that one there you go fantastic there you go guys so the build is completed right so yeah so that is so guys you know that is how you can configure uh your Azure VM as a build agent and then that is how you know you can run build using Azure devops pipeline thank you for watching this video folks thank you
Info
Channel: DevOps Coach
Views: 13,594
Rating: undefined out of 5
Keywords: Azure Build Agent Setup, How to Setup Azure Build agents
Id: Hy6fne9oQJM
Channel Id: undefined
Length: 22min 49sec (1369 seconds)
Published: Thu Jan 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.