-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathazure-pipelines.yml
139 lines (124 loc) · 5.47 KB
/
azure-pipelines.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Pipeline to validate and deploy ARM templates
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
variables:
# Deployment location
location: 'West Europe'
# Artifact name
artifactName: 'azure.linked-arm-templates'
stages:
- stage: Publish
displayName: Publish
jobs:
- job: PublishdJob
displayName: Copy and Publish Artifacts
pool:
vmImage: 'windows-latest'
steps:
- task: CopyFiles@2
displayName: Copy files
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish build artifacts
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: '$(artifactName)'
- stage: DeployToTestEnvironment
displayName: Deploy to test
dependsOn: Publish
jobs:
- deployment: DeploymentJob
displayName: Deploy ARM templates
pool:
vmImage: 'windows-latest'
environment: 'test'
strategy:
runOnce:
deploy:
steps:
- task: AzureResourceManagerTemplateDeployment@3
displayName: Create a resource group
inputs:
deploymentScope: 'Subscription'
ConnectedServiceName: $(subscriptionName)
subscriptionName: $(subscriptionId)
location: $(location)
templateLocation: 'Linked artifact'
csmFile: '$(Agent.BuildDirectory)\$(artifactName)\resource-group\azuredeploy.json'
csmParametersFile: '$(Agent.BuildDirectory)\$(artifactName)\resource-group\azuredeploy.parameters.json'
deploymentMode: 'Incremental'
deploymentOutputs: 'armOutputs'
- task: AzurePowerShell@4
displayName: Get the resource group name
inputs:
azureSubscription: $(subscriptionName)
scriptType: 'InlineScript'
Inline: |
$var=ConvertFrom-Json '$(armOutputs)'
$value=$var.resourceGroupName.value
Write-Host "##vso[task.setvariable variable=resourceGroupName;]$value"
azurePowerShellVersion: 'latestVersion'
pwsh: true
- task: AzureResourceManagerTemplateDeployment@3
displayName: Create a storage account for deployment artifacts
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: $(subscriptionName)
subscriptionName: $(subscriptionId)
action: 'Create Or Update Resource Group'
resourceGroupName: '$(resourceGroupName)'
location: $(location)
templateLocation: 'Linked artifact'
csmFile: '$(Agent.BuildDirectory)\$(artifactName)\storage-account-for-artifacts\azuredeploy.json'
csmParametersFile: '$(Agent.BuildDirectory)\$(artifactName)\storage-account-for-artifacts\azuredeploy.parameters.json'
deploymentMode: 'Incremental'
deploymentOutputs: 'armOutputs'
- task: AzurePowerShell@4
displayName: Get the storage account and its container names
inputs:
azureSubscription: $(subscriptionName)
scriptType: 'InlineScript'
Inline: |
$var=ConvertFrom-Json '$(armOutputs)'
$value=$var.storageAccountName.value
Write-Host "##vso[task.setvariable variable=storageAccountName;]$value"
$value=$var.storageContainerName.value
Write-Host "##vso[task.setvariable variable=storageContainerName;]$value"
azurePowerShellVersion: 'latestVersion'
pwsh: true
- task: AzureFileCopy@3
displayName: Copy deployment artifacts to the storage account
inputs:
sourcePath: '$(Agent.BuildDirectory)\$(artifactName)\linked-templates'
azureSubscription: $(subscriptionName)
destination: azureBlob
storage: $(storageAccountName)
containerName: $(storageContainerName)
blobPrefix: 'linked-templates'
cleanTargetBeforeCopy: true
outputStorageUri: artifactsLocation
outputStorageContainerSasToken: artifactsLocationSasToken
sasTokenTimeOutInMinutes: 30
- task: AzureResourceManagerTemplateDeployment@3
displayName: Deploy resources to the resource group
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: $(subscriptionName)
subscriptionName: $(subscriptionId)
action: 'Create Or Update Resource Group'
resourceGroupName: '$(resourceGroupName)'
location: $(location)
templateLocation: 'Linked artifact'
csmFile: '$(Agent.BuildDirectory)\$(artifactName)\main-template\azuredeploy.json'
csmParametersFile: '$(Agent.BuildDirectory)\$(artifactName)\main-template\azuredeploy.parameters.json'
overrideParameters: '-_artifactsLocation $(artifactsLocation) -_artifactsLocationSasToken $(artifactsLocationSasToken)'
deploymentMode: 'Incremental'
deploymentOutputs: 'armOutputs'