-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yaml
138 lines (131 loc) · 4.97 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
trigger:
batch: true
branches:
include:
- main
resources:
repositories:
- repository: cnp-azuredevops-libraries
type: github
ref: refs/heads/master
name: hmcts/cnp-azuredevops-libraries
endpoint: 'hmcts'
parameters:
- name: overrideAction
type: string
default: plan
values:
- plan
- apply
- destroy
- name: environment_components
type: object
default:
- deployment: 'sds_ptl'
environment: 'ptl'
component: 'infra'
service_connection: 'DTS-SHAREDSERVICESPTL'
dependsOn: 'Build'
- deployment: 'cft_ptl'
environment: 'ptl'
component: 'infra'
service_connection: 'DTS-CFTPTL-INTSVC'
dependsOn: 'Build'
variables:
- name: timeoutInMinutes
value: 60
- name: agentPool
value: ubuntu-22.04
- name: build
value: $(Build.BuildNumber)
- name: product
value: alerts
- name: terraformInitSubscription
value: 04d27a32-7a07-48b3-95b8-3c8691e1a263
- template: vars/input-variables.yaml@cnp-azuredevops-libraries
stages:
- stage: Precheck
jobs:
- job:
pool:
vmImage: ${{ variables.agentPool }}
timeoutInMinutes: ${{ variables.timeoutInMinutes }}
steps:
- template: steps/terraform-precheck.yaml@cnp-azuredevops-libraries
parameters:
keyvaultName: 'infra-vault-nonprod'
keyvaultSecret: 'azure-devops-sp-token'
serviceConnection: 'DCD-CFT-Sandbox'
overrideAction: ${{ parameters.overrideAction }}
- stage: Build
dependsOn: Precheck
jobs:
- job: BuildArtifacts
pool:
vmImage: ${{ variables.agentPool }}
timeoutInMinutes: ${{ variables.timeoutInMinutes }}
steps:
- bash: |
npm install
npm run build --if-present
npm prune --production
displayName: Install dependencies
workingDirectory: $(System.DefaultWorkingDirectory)
- bash: npm prune --production
displayName: Prune dependencies
workingDirectory: $(System.DefaultWorkingDirectory)
- bash: |
zip -r $(System.ArtifactsDirectory)/build$(Build.BuildId).zip . --exclude @.funcignore --exclude .funcignore
displayName: Archive files
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(System.ArtifactsDirectory)/build$(Build.BuildId).zip'
artifactName: 'alerts-to-slack'
- ${{ each deployment in parameters.environment_components }}:
- stage: ${{ deployment.deployment }}
displayName: "Infra - ${{ deployment.deployment }}"
dependsOn: ${{ deployment.dependsOn }}
jobs:
- job: TerraformPlanApply
pool:
vmImage: ${{ variables.agentPool }}
timeoutInMinutes: ${{ variables.timeoutInMinutes }}
steps:
- template: steps/terraform.yaml@cnp-azuredevops-libraries
parameters:
overrideAction: ${{ parameters.overrideAction }}
environment: ${{ deployment.environment }}
component: ${{ deployment.component }}
serviceConnection: ${{ deployment.service_connection }}
terraformInitSubscription: ${{ variables.terraformInitSubscription }}
product: ${{ variables.product }}
- task: DownloadPipelineArtifact@2
displayName: Download artifact
condition: |
or(
and(succeeded(), eq('${{ parameters.overrideAction }}', 'apply')),
and(succeeded(), eq(variables['isMain'], true), eq(variables['isAutoTriggered'], true))
)
inputs:
buildType: 'current'
artifactName: 'alerts-to-slack'
- task: AzureFunctionApp@2
displayName: Publish to Azure Function
condition: |
or(
and(succeeded(), eq('${{ parameters.overrideAction }}', 'apply')),
and(succeeded(), eq(variables['isMain'], true), eq(variables['isAutoTriggered'], true))
)
inputs:
azureSubscription: ${{ deployment.service_connection }}
appType: functionApp
${{ if and(eq( deployment['environment'], 'stg'), contains( deployment['deployment'], 'cft')) }}:
appName: "cft-${{ variables.product }}-slack-aat"
${{ elseif and(eq( deployment['environment'], 'test'), contains( deployment['deployment'], 'cft')) }}:
appName: "cft-${{ variables.product }}-slack-perftest"
${{ elseif and(ne( deployment['environment'], 'stg'), contains( deployment['deployment'], 'cft')) }}:
appName: "cft-${{ variables.product }}-slack-${{ deployment.environment }}"
${{ elseif contains( deployment['deployment'], 'sds') }}:
appName: "sds-${{ variables.product }}-slack-${{ deployment.environment }}"
package: $(Pipeline.Workspace)/**/*.zip
deploymentMethod: 'auto'