Skip to content

21bshwjt/AksBuildAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Azure DevOps Self Hosted Agents

Run Self-Hosted Windows Agent from Azure Container

  • Clone the Repo & login in Azure

Dockerfile & start.ps1 taken from MSFT KB

# Clone the repo
git clone https://github.com/21bshwjt/AksBuildAgent.git
# Change Directory path
cd C:\aksbuildagent\AksBuildAgent
# Login to Azure
az login
# Set to your Subscription
az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  • Create an ACR.
# Create a Resource Group
az group create --name aksbuildagent --location westus2
# Create Azure Container Registry
az acr create --resource-group aksbuildagent --name <Your_ACR_Name> --sku Basic
  • Build the Dockerfile in the Cloud with a Task.
az acr build --registry <Your_ACR_Name> -t buildagent:v1.0 --platform windows .

Go to your ACR --> Access Keys --> Admin user (Enable that option; pls refer the below screenshot)

  • Create an Azure Container Instance.
az container create --resource-group aksbuildagent --name <ACR_Name> --image <Image_URL> --restart-policy OnFailure --registry-login-server <ACR_Login_Server> --registry-username <ACR_UserName> --registry-password <Password> --os-type Windows --environment-variables 'AZP_URL=<AZDO_URL>' 'AZP_TOKEN=<PAT>' 'AZP_POOL=<Pool_Name>' 'AZP_AGENT_NAME=<Agent_Name>' 
  • After few minutes agent will become available for the pipelines.

  • Add agent pool with the pipeline.

How to add agent with the pipeline ?

Please check the 'pool:' section.

trigger:
- main

pool:
  name: akspool
  demand:
   - agent.name -equals DockerAgent1

variables:
- name: ResourceGroup
  value: arm_storageacct01
- name: ResourceGroup01
  value: arm_storageacct02
- name: AzureDataCenter
  value: 'Central US'

resources:
  repositories:
    - repository: biswajit
      type: git
      name: 'Simple Server/Buildtemplates'

steps:
- template: storage_tag_containers01.yml@biswajit
- template: storage_tag_containers02.yml@biswajit

We have tested Windows Self-Hosted build agent into Azure Container but that can be done from local machine and AKS Cluster as well.

  • Self-Hosted agent can be run from local machine where we need to have Docker install. Please refer MSFT KB to run the image from local machine.
  • Self-Hosted agent can be run from Azure Container.
  • Self-Hosted agent can be run from AKS cluster & recommended for production.