agent-sp
Architecture: any
Architecture: any
name: agent-sp
variables:
- name: agentVersion
value: "latest"
required: true
- name: clientSecret
secret: true
required: true
- name: clientId
required: true
- name: tenantId
required: true
- name: agentPassword
required: true
- name: devopsUrls
required: true
- name: poolName
value: default
required: true
- name: agentName
required: true
fodder:
- name: agent-user
type: cloud-config
secret: true
content: |
users:
- name: vsts-agent
groups: [ "Administrators" ]
passwd: {{ agentPassword }}
- name: azure-agent
type: shellscript
secret: true
filename: azure_agent.ps1
content: |
#ps1_sysnative
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3.0
# Expand-Archive is a script module and will take its preferences from the global scope.
# See https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/77#issuecomment-601947496
$global:ProgressPreference = 'SilentlyContinue'
if ([System.Net.ServicePointManager]::SecurityProtocol -ne 0) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
}
$version = '{{ agentVersion }}'
if ($version -eq 'latest') {
$releaseInfo = Invoke-RestMethod https://api.github.com/repos/Microsoft/azure-pipelines-agent/releases/latest -UseBasicParsing
$version = $releaseInfo.tag_name -replace '^v', ''
}
Invoke-WebRequest -Uri "https://download.agent.dev.azure.com/agent/$version/vsts-agent-win-x64-$version.zip" -OutFile C:\vsts-agent.zip -UseBasicParsing
Expand-Archive -Path C:\vsts-agent.zip -DestinationPath C:\a
Remove-Item -Path C:\vsts-agent.zip
Set-Location C:\a
.\config.cmd --unattended --url '{{ devopsUrls }}' --auth SP --clientId '{{ clientId }}' --tenantId '{{ tenantId }}' --clientSecret '{{ clientSecret }}' --pool '{{ poolName }}' --agent '{{ agentName }}' --acceptTeeEula --replace --runAsService --windowsLogonAccount vsts-agent --windowsLogonPassword '{{ agentPassword }}'
if ($LASTEXITCODE -ne 0) {
throw "config.cmd failed with exit code $LASTEXITCODE"
}