-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathazure-pipelines.yml
176 lines (147 loc) · 5.58 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
variables:
ResourceGroupName: 'SonarQube-rg'
ContainerRegistryName: 'chcontainerregistrymain'
AdminUserName: 'chcontainerregistrymain'
stages:
- stage: BuildSonarQubeTerraformFiles
jobs:
- job: 'BuildSonarQubeTerraformFiles'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/Terraform/SonarQube'
ArtifactName: 'SonarQubeCore'
publishLocation: 'Container'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/Terraform/ContainerRegistry'
ArtifactName: 'ContainerRegistry'
publishLocation: 'Container'
- stage: 'DeployContainerRegistry'
dependsOn: BuildSonarQubeTerraformFiles
condition: succeeded()
jobs:
- job: 'DeployContainerRegistry'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'ContainerRegistry'
downloadPath: '$(System.DefaultWorkingDirectory)'
displayName: 'Download Azure ResourceGroup Artifact'
- task: TerraformInstaller@0
inputs:
terraformVersion: '0.12.20'
displayName: 'Install Terraform'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/ContainerRegistry'
backendServiceArm: 'MSDN'
backendAzureRmResourceGroupName: 'tfstate'
backendAzureRmStorageAccountName: 'chsonarquberesourcegroup'
backendAzureRmContainerName: 'terraform-state'
backendAzureRmKey: 'terraform.tfstate'
displayName: 'Terrafom Init'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(System.DefaultWorkingDirectory)/ContainerRegistry'
commandOptions: "-out main.tfplan -var=containerRegistryName=$(ContainerRegistryName)"
environmentServiceNameAzureRM: 'MSDN'
displayName: 'Terraform Plan'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/ContainerRegistry'
commandOptions: 'main.tfplan'
environmentServiceNameAzureRM: 'MSDN'
displayName: 'Terraform Apply'
- stage: 'BuildSonarqubeDockerImage'
dependsOn: DeployContainerRegistry
condition: succeeded()
jobs:
- job: 'BuildDeployDockerImage'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'SonarQubeCore'
downloadPath: '$(System.DefaultWorkingDirectory)'
displayName: 'Download Sonarqube Artifact'
- task: Docker@2
displayName: 'Login to Docker Hub'
inputs:
command: login
containerRegistry: DockerHub
- task: Docker@2
displayName: 'Login to ACR'
inputs:
command: login
containerRegistry: AzureContainerRegistry
- task: Docker@2
displayName: 'Push image to azure acr'
inputs:
command: buildAndPush
containerRegistry: AzureContainerRegistry
Dockerfile: '$(System.DefaultWorkingDirectory)/SonarQubeCore/Dockerfile'
repository: 'sonarqube'
- stage: 'DeployAzureWebApp'
dependsOn: BuildSonarqubeDockerImage
condition: succeeded()
jobs:
- job: 'DeployAzureWebApp'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'SonarQubeCore'
downloadPath: '$(System.DefaultWorkingDirectory)'
displayName: 'Download Sonarqube Artifact'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/SonarQubeCore'
backendServiceArm: 'MSDN'
backendAzureRmResourceGroupName: 'tfstate'
backendAzureRmStorageAccountName: 'ch45947'
backendAzureRmContainerName: 'terraform-state'
backendAzureRmKey: 'terraform.tfstate'
displayName: 'Terrafom Init'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(System.DefaultWorkingDirectory)/SonarQubeCore'
commandOptions: '-out main.tfplan -var=AdminUserName=$(AdminUserName) -var=AdminPassword=$(AdminPassword) -var=resourcegroupName=$(ResourceGroupName) -var=containerRegistrySASToken=$(containerregistrySASToken) -var=BuildId=$(Build.BuildId)'
environmentServiceNameAzureRM: 'MSDN'
displayName: 'Terraform Plan'
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/SonarQubeCore'
commandOptions: 'main.tfplan'
environmentServiceNameAzureRM: 'MSDN'
displayName: 'Terraform Apply'