-
Notifications
You must be signed in to change notification settings - Fork 156
/
azure-pipelines.yaml
140 lines (124 loc) · 4.14 KB
/
azure-pipelines.yaml
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
trigger:
branches:
include:
- master
variables:
buildConfiguration: 'Release'
location: 'West US 2'
acrHostName: 'cswebappdocker004acr.azurecr.io'
acrName: 'cswebappdocker004acr'
rgName: 'cswebappdocker004-rg'
imageName: 'cswebappdocker004'
webAppName: 'cswebappdocker004'
stages:
# Build Stage
- stage: BuildAndTest
jobs:
- job: BuildAndTest
pool:
vmImage: 'Ubuntu-16.04'
steps:
# Create or update the ACR resource
- task: AzureResourceGroupDeployment@2
displayName: 'Azure Deployment:Create Azure Container Registry'
inputs:
azureSubscription: 'AzureSC'
resourceGroupName: '$(rgName)'
location: $(location)
csmFile: '$(System.DefaultWorkingDirectory)/**/containerRegistry-template.json'
overrideParameters: '-registryName "$(acrName)" -registryLocation "$(location)" -registrySku standard'
- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 2.2.x
installationPath: $(Agent.ToolsDirectory)/dotnet
# Restore dependencies
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
# Build app
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
# Run unit tests
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*UnitTests/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
# Publish the app
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(System.DefaultWorkingDirectory)/PublishedWebApp'
zipAfterPublish: false
# Build container image
- task: Docker@1
displayName: 'Build container image'
inputs:
azureSubscriptionEndpoint: 'AzureSC'
azureContainerRegistry: '$(acrHostName)'
imageName: '$(imageName):$(Build.BuildId)'
useDefaultContext: false
buildContext: '$(System.DefaultWorkingDirectory)/PublishedWebApp'
# Push container image
- task: Docker@1
displayName: 'Push container image'
inputs:
azureSubscriptionEndpoint: 'AzureSC'
azureContainerRegistry: '$(acrHostName)'
command: 'Push an image'
imageName: '$(imageName):$(Build.BuildId)'
# Copy ARM templates
- task: CopyFiles@2
displayName: 'Copy ARM templates'
inputs:
SourceFolder: ArmTemplates
TargetFolder: '$(build.artifactstagingdirectory)'
# Publish the app as an artifact
- publish: $(Build.StagingDirectory)
artifact: app
# Staging release
- stage: Staging
jobs:
- job: Release
pool:
vmImage: 'Ubuntu-16.04'
steps:
# Don't clone the repo
- checkout: none
# Download the published application artifact
- download: current
artifact: app
# Create or update Azure App Service
- task: AzureResourceGroupDeployment@2
displayName: 'Azure Deployment:Create Azure App Service'
inputs:
azureSubscription: 'AzureSC'
resourceGroupName: '$(rgName)'
location: '$(location)'
csmFile: '$(Pipeline.Workspace)/**/container-webapp-template.json'
overrideParameters: '-webAppName $(webAppName) -hostingPlanName $(webAppName) -appInsightsLocation "$(location)" -sku "S1 Standard" -registryName $(acrName) -registryLocation "$(location)" -registrySku standard -imageName $(imageName):$(Build.BuildId)'
# Deploy App Service
- task: AzureRmWebAppDeployment@3
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: 'AzureSC'
appType: applinux
WebAppName: $(webAppName)
DockerNamespace: $(acrHostName)
DockerRepository: $(webAppName)
DockerImageTag: '$(Build.BuildId)'
WebAppUri: webAppUrl
TakeAppOfflineFlag: true
UseWebDeploy: true
RenameFilesFlag: true