[Microsoft] Run Azure Pipelines (VSTS) Agent on Docker or Azure Container Instance

Azure Pipelines Run the agent with Docker.

What is Azure Pipelines?

A service that builds / deploys like Jenkins.

What is Azure Pipelines Agent?

It is a daemon that actually operates the build and deploy process in response to instructions from Azure Pipelines.

Azure Pipelines comes with a free version, but there is a monthly run time limit. By preparing your own agent, you can use it without the maximum time.

What you need in advance

Organization name

See the URL for Azure DevOps. I think it looks like https://dev.azure.com/hogehoge. This is the part of hogehoge.

Personal Access Token

This is what the agent needs to connect to Azure DevOps.

Click here for [How to get Personal Access Token](https://docs.microsoft.com/ja-jp/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs = preview-page).

Set the following as the scope.

Run with Docker

The official image of Micorosoft is Deprecated, so I created it though I'm afraid. sengokyu/azure-pipelines-agent:latest Pull as usual.

docker pull sengokyu/azure-pipelines-agent

At the time of execution, give the organization name and Personal Access Token prepared in advance as environment variables.

Variable name value
ORG Organization name
TOKEN Personal Access Token
docker run -d -e TOKEN=${PAT} -e ORG=${ORG} sengokyu/azure-pipelines-agent

Run on Azure Container Instance

Deploy using an ARM template.

The resource definition part of the ARM template. The whole thing is on GitHub.

template.json


  "resources": [
    {
      "name": "[parameters('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "containers": [
          {
            "name": "[parameters('agent')]",
            "properties": {
              "image": "[variables('containerImage')]",
              "resources": {
                "requests": {
                  "cpu": "[parameters('cpu')]",
                  "memoryInGb": "[parameters('memoryInGb')]"
                }
              },
              "environmentVariables": [
                { "name": "TOKEN", "secureValue": "[parameters('token')]" },
                { "name": "ORG", "value": "[parameters('org')]" },
                { "name": "POOL", "value": "[parameters('pool')]" },
                { "name": "AGENT", "value": "[parameters('agent')]" }
              ]
            }
          }
        ],
        "osType": "Linux",
        "restartPolicy": "Never"
      }
    }
  ]

Create a file that describes each parameter.

parameters.json


{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "containerGroupName": { "value": "vsts-agent" },
    "pool": { "value": "Default" },
    "agent": { "value": "vsts-agent-on-aci" },
    "token": { "value": "YourPersonalAccessToken" },
    "org": { "value": "YourOrganizationName" },
    "cpu": { "value": 4 },
    "memoryInGb": { "value": 8 }
  }
}

Execute the az command.

az deployment group create -f template.json -p @parameters.json -g ResourceGroupName

Recommended Posts

[Microsoft] Run Azure Pipelines (VSTS) Agent on Docker or Azure Container Instance
Run React on a Docker container
Run GUI application on Docker container
Run PureScript on a Docker container
Run NordVPN on Docker (Windows) Ubuntu container
Run GUI application on Docker container (Japanese input)
Run the Android emulator on Docker using Android Emulator Container Scripts
Run phpunit on Docker
Run VS Code on Docker
Run openvpn on Docker (windows)
Run SSE (Server-Sent-Event) samples on docker
Run puppeteer-core on Heroku (Docker edition)
Run the AWS CLI on Docker
How to run JavaFX on Docker
Summary of Docker understanding by beginners ⑤ ~ Until deploying docker container on EC2 instance ~