-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
101 lines (92 loc) · 3 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
trigger:
- main
resources:
- repo: self
variables:
- group: 'common'
- name: K8S_CONTAINER_NAME
value: chatbot-container
- name: K8S_DEPLOYMENT_NAME
value: chatbot-deployment
- name: K8S_DEPLOYMENT_NAMESPACE
value: chatbot-tck
- name: AZURE_ACR_IMAGE_NAME
value: chatbot-app
- name: SONAR_PROJECT_NAME
value: $(AZURE_ACR_IMAGE_NAME)
- name: AZURE_AKS_SERVICE_CONNECTION
value: glia-azure-kubernetes-chatbot
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Test
jobs:
- job: Test
steps:
- task: SonarQubePrepare@5
inputs:
SonarQube: $(SONAR_CONNECTION)
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: $(AZURE_ACR_IMAGE_NAME)
cliProjectName: $(SONAR_PROJECT_NAME)
cliSources: '.'
- task: CmdLine@2
inputs:
displayName: 'Remove branch name from SonarQube params'
script: |
params=$(echo "${SONARQUBE_SCANNER_PARAMS}" | sed -e 's/"sonar.branch.name":"[^"]*",//')
echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS;]$params"
- task: SonarQubeAnalyze@5
- task: SonarQubePublish@5
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: $(AZURE_ACR_NAME)
repository: $(AZURE_ACR_IMAGE_NAME)
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
tags: |
$(TAG)
latest
- stage: Deploy
dependsOn: Build
jobs:
- deployment: Deploy
environment: 'dev'
strategy:
runOnce:
deploy:
steps:
- task: Kubernetes@1
displayName: 'Deploy to AKS'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(AZURE_AKS_SERVICE_CONNECTION)
namespace: $(K8S_DEPLOYMENT_NAMESPACE)
command: 'set'
arguments: |
image deployment/$(K8S_DEPLOYMENT_NAME) $(K8S_CONTAINER_NAME)=$(AZURE_ACR_ADDRESS)/$(AZURE_ACR_IMAGE_NAME):$(TAG)
- task: Kubernetes@1
displayName: Check succesfuly deploy image to kubernetes
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(AZURE_AKS_SERVICE_CONNECTION)
namespace: $(K8S_DEPLOYMENT_NAMESPACE)
command: rollout
arguments: status deployment/$(K8S_DEPLOYMENT_NAME) -w
- task: Kubernetes@1
displayName: Failure Logs
condition: failed()
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(AZURE_AKS_SERVICE_CONNECTION)
namespace: $(K8S_DEPLOYMENT_NAMESPACE)
command: logs
arguments: -l service=$(K8S_DEPLOYMENT_NAME) -c $(K8S_DEPLOYMENT_NAME)