In this article, we will learn how we can create custom agent for our azure pipeline. We can use this agent in the auto deployment process to VM machine.
This agent are the one which I mentioned in the article here Auto Deploy To Azure VM Using TFS Portal (Part 1) – The Code Hubs. So, it will simply build your code from the connected repository and publish it to the VM machine.
The device which we are using as agent must have all the application which are required to build the project. For example, if you want to deploy the .Net Core project then the agent machine must have the .Net frameworks.
Go to the Organization Setting > Agent Pool. Click the new agent button to create the agent.
Download the zip file using the download button in the popup
Once the download is completed. Open power shell (“Run as Administrator”) in the agent device. Move to the root folder using cd.. command. Then fire the below command. First command will create the agent folder.
mkdir agent ; cd agent
Then once the directory is created, fire the below command to extract the downloaded files.
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\vsts-agent-win-x64-2.186.1.zip", "$PWD")
After than we need to configure the agent. So, fire the below command to configure it.
Once you fire the above command it will ask few questions. First is to enter the server url. It will be your azure devops service url.
Then it will ask for authentication type. Just press enter to move forward. It will take PAT (Personal Access Token) as default
Now, you will need a personal access token to move forward. So, we need to generate it from the setting section.
Click “New Token” button and enter the name for the token. I have used “Agent” as the name, as I am creating this key for agent. Select full access for scope.
Once you create the token it will give a long string. Copy the string and save it in your system. Please save it as we won’t get it again from the system.
Use the token we get from above step to move forward.
Once you enter the token, it will connect to the server. After that it will ask for agent registration. Press enter for agent pool question as we are creating agent in default agent pool. Then, it will ask for agent name. Enter the agent name which you want for that device. It will be displayed in our Azure devOps Agent section.
Then it will scan for capabilities. Once the agent is successfully added, it will ask for the work folder. This will be the folder name where the build files will be saved. To use the default folder (_work) just press enter. Then again press enter for N in the unzip question
After that it will ask to run agent as service. We need to give ‘Y’ for this question as we want our agent to be available without user interaction.
After that it will ask for account to use for service. Just press enter for the default login. Once the authentication setting is saved then agent created sucessfully.
We can check the agent in the devOps agent list. It will show as online if the process is successfully done.