This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathazure-pipelines.yaml
128 lines (112 loc) · 4.1 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
name: $(Build.BuildId)
# Triggers Pipeline only on Master
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- LICENSE
# Disables triggering Pipeline run at creation of every Pull Request
pr: none
# Global variables for the pipeline
variables:
- group: 'AWS ECR-PUSH PROD'
- name: 'vmImage'
value: 'ubuntu-latest'
- name: 'k8s-service-connection'
value: 'Kubernetes-Hellman-selfservice-deploy'
- name: 'kubernetes-namespace'
value: 'selfservice'
stages:
# Continuous Integration steps
- stage: CI
displayName: 'Continuous Integration'
# Validation jobs
jobs:
# Build jobs
- job: Build
pool:
vmImage: $(vmImage)
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core sdk'
inputs:
packageType: sdk
version: 3.1.100
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: NodeTool@0
inputs:
versionSource: 'spec' # 'spec' | 'fromFile'. Required. Source of version. Default: spec.
versionSpec: '14.x' # string. Optional. Use when versionSource = spec. Version Spec. Default: 6.x.
#versionFilePath: # string. Optional. Use when versionSource = fromFile. Path to the .nvmrc file.
#checkLatest: false # boolean. Check for Latest Version. Default: false.
#force32bit: false # boolean. Use 32 bit version on x64 agents. Default: false.
- bash: |
set -eu -o pipefail
sudo pip install setuptools
sudo pip install awscli
chmod +x ./pipeline.sh
./pipeline.sh $(Build.BuildId) $(System.DefaultWorkingDirectory)
displayName: Pipeline Bash Script
env:
AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testRunner: VSTest
testResultsFiles: testresults.trx
searchFolder: '$(System.DefaultWorkingDirectory)/output'
condition: succeededOrFailed()
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/output/coverage.cobertura.xml'
- task: PublishBuildArtifacts@1
displayName: "Publish Artifact: manifests"
inputs:
PathtoPublish: k8s
ArtifactName: manifests
# Continuous Deployment steps
- stage: CD
displayName: 'Continuous Deployment'
dependsOn: CI
# Run CD only if CI succeeds and if pipeline runs from Master branch
condition: and(succeeded('CI'), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment: K8s
displayName: 'Deploy to Kubernetes'
pool:
vmImage: $(vmImage)
environment: 'Hellman'
strategy:
runOnce:
deploy:
steps:
# Download manifest from current artifacts pipeline
- download: current
artifact: manifests
displayName: 'Download Artifact: manifests'
# Replace token values in yaml files with pipeline variables
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace tokens in yaml files'
inputs:
rootDirectory: '$(Pipeline.Workspace)/manifests/'
targetFiles: '*.yml'
tokenPrefix: '$('
tokenSuffix: ')'
# Upload the modified Kubernetes manifests to current Pipeline for easy debugging
- publish: $(Pipeline.Workspace)/manifests/
artifact: deployed-manifests
displayName: 'Publish Artifact: manifests'
# Apply Kubernetes manifests
- task: Kubernetes@1
displayName: 'Apply manifests'
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: '$(k8s-service-connection)'
namespace: '$(kubernetes-namespace)'
command: apply
arguments: '-f $(Pipeline.Workspace)/manifests/'