forked from panda0107/AzureDevOps-CICD-Hands-on-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
85 lines (66 loc) · 2.9 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
# 以 Docker Container 方式部署一個 Node.js 應用程式至 Azure Web App for Containers Linux
# 更多資訊請參閱 https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment
# 各種語言 Azure DevOps Build YAML 範本可參閱 https://github.com/microsoft/azure-pipelines-yaml/tree/master/templates
trigger:
- master
resources:
- repo: self
variables:
# ========================================================================
# 主要變數,請填入您對應的內容
# ========================================================================
# 變數 Azure.ResourceGroupName 值請填入您所建立的的 Azure 資源群組名稱.
Azure.ResourceGroupName: 'myDevOpsResourceGroup'
# 變數 Azure.ServiceConnectionId 請填入您在 Azure DevOps 內建立的 Service connections 名稱.
Azure.ServiceConnectionId: 'MyAzureConnection'
# 變數 Azure.Location 填入您所建立的的 Azure 資源群組名稱所在之資料中心.
Azure.Location: 'southeastasia'
# 變數 ACR.Name 請填入您所建立的 Azure Container Registry (ACR) 名稱.
ACR.Name: '<您的 ACR 名稱>'
# 變數 Web.Name 請填入您所建立的 Azure Web App for Containers Linux 名稱
WebApp.Name: '<您的 Azure Web App for Containers Linux 名稱>'
# 變數 ServicePlan.Name 請填入您所建立的 Azure App Service Plan 名稱
ServicePlan.Name: 'mydevops-appserviceplan'
# 變數 MyImageName 請填入 Docker Image 標籤名稱,未來會以 MyImageName:Build# 方式放在 ACR 內
MyImageName: 'nodejs-app'
# ========================================================================
# 衍伸變數與除錯用途設定
# ========================================================================
ACR.ImageName: '$(MyImageName):$(Build.BuildId)'
ACR.FullName: '$(ACR.Name).azurecr.io'
System.Debug: 'false'
jobs:
- job: BuildImage
displayName: Build
condition: succeeded()
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@1
displayName: 'Build an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: build
dockerFile: '**/Dockerfile'
- task: Docker@1
displayName: 'Push an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: push
- job: DeployApp
displayName: Deploy
dependsOn: BuildImage
condition: succeeded()
pool:
vmImage: 'ubuntu-latest'
steps:
- task: AzureWebAppContainer@1
displayName: 'Azure Web App on Container Deploy: $(WebApp.Name)'
inputs:
azureSubscription: '$(Azure.ServiceConnectionId)'
appName: $(WebApp.Name)
imageName: '$(ACR.FullName)/$(ACR.ImageName)'