-
Notifications
You must be signed in to change notification settings - Fork 8
/
pipeline.yml
85 lines (79 loc) · 3.11 KB
/
pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: $(moduleName)-$(moduleVersion)
variables:
- template: pipeline.variables.yml
- template: ../Parameters/parameters.yml
trigger:
batch: true
branches:
include:
- master
paths:
include:
- PipelineAgents/*
exclude:
- PipelineAgents/*/readme.md
stages:
- stage: Create
jobs:
- job: Create
displayName: Create Container Registry
pool:
vmImage: $(vmImage)
steps:
- task: AzureCLI@2
enabled: true
displayName: Create ACR and Build Docker Image
inputs:
azureSubscription: $(serviceConnection)
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az group create --name $(resourceGroupName) --location "$(location)"
az acr create --resource-group $(resourceGroupName) --name $(acrName) --sku Basic --admin-enabled true
az acr login --name $(acrName)
New-Item "$(modulePath)/.token" -ItemType File -Value "$(agentPoolToken)"
az acr build --image "apa_$(imageOS)" --registry $(acrName) --file "$(modulePath)/dockerfile" "$(modulePath)" #--platform windows
Remove-Item "$(modulePath)/.token" -Force
- stage: Deploy
jobs:
- job: 'Deploy'
displayName: Deploy Container Instances
pool:
vmImage: $(vmImage)
steps:
- task: AzurePowerShell@4
displayName: 'Start and connect Pipeline Agents'
inputs:
azureSubscription: $(serviceConnection)
ScriptType: InlineScript
azurePowerShellVersion: LatestVersion
Inline: |
$containers = @()
$envVars = @{
"AZP_URL"="$(adoUrl)";
#"AZP_TOKEN"="$(agentPoolToken)";
"AZP_TOKEN_FILE"="/azp/.token";
"AZP_POOL"="$(agentPoolName)"
}
$registry = Get-AzContainerRegistry -ResourceGroupName $(resourceGroupName) -Name $(acrName)
$credentials = Get-AzContainerRegistryCredential -Registry $registry
$registryCredentials= New-Object System.Management.Automation.PSCredential ("$($registry.Name)", (ConvertTo-SecureString "$($credentials.Password)" -AsPlainText -Force))
$image = "$($registry.LoginServer)" + "/" + "apa_" + "$(imageOS)"
$osType = if ("$(imageOS)" -eq "servercore") {"Windows"} else {"Linux"}
for ($i=1; $i -le $(instanceCount); $i++) {
$containerName = "$(containerNamePrefix)" + "-00$i"
Write-Output "Creating container $containerName ..."
$envVars["AZP_AGENT_NAME"] = $containerName
New-AzContainerGroup `
-ResourceGroupName $(resourceGroupName) `
-Name "$containerName" `
-Image "$image" `
-RegistryCredential $registryCredentials `
-Cpu 1 `
-MemoryInGB 4 `
-OsType $osType `
-RestartPolicy OnFailure `
-EnvironmentVariable $envVars
$containers += "$containerName"
}
Write-Output $containers