-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtask_azure_sql_backup_prod.yaml
More file actions
126 lines (116 loc) · 4.14 KB
/
task_azure_sql_backup_prod.yaml
File metadata and controls
126 lines (116 loc) · 4.14 KB
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
---
name: $(Build.SourceBranchName)-$(Date:yyyyMMdd)_$(Rev:r)
trigger: none
pr: none
schedules:
- cron: "0 2 * * *" # Run daily at 2:00 AM UTC
displayName: 'Run Backup'
branches:
include:
- main
always: true
resources:
repositories:
- repository: dtos-devops-templates
type: github
name: NHSDigital/dtos-devops-templates
ref: d4f16d361f70210e56cb698f5d4bbba14a42c892
endpoint: NHSDigital
variables:
- name: hostPoolName
value: private-pool-prod-uks
- group: PROD_core_backend
- group: PROD_image_pipelines
- name: TF_VERSION
value: 1.14.4
- name: TF_PLAN_ARTIFACT
value: tf_plan_core_PROD
- name: TF_DIRECTORY
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-core
- name: ENVIRONMENT
value: production
stages:
- stage: db_backup_stage
displayName: Database backup stage
pool:
name: $(hostPoolName)
jobs:
- job: db_backup
displayName: Create Database Backup and Upload to Storage Account
steps:
- checkout: self
- checkout: dtos-devops-templates
- template: .azuredevops/templates/steps/app-container-job-start.yaml@dtos-devops-templates
parameters:
serviceConnection: $(SERVICE_CONNECTION)
targetSubscriptionId: $(TF_VAR_TARGET_SUBSCRIPTION_ID)
resourceGroupName: $(RESOURCE_GROUP_NAME_SQL)
jobName: ca-db-backup-uksouth
maxPollingAttempts: 240
pollingIntervalSeconds: 15
- job: set_db_backup_stage_status
displayName: Set Database Backup Status
pool:
name: $(hostPoolName)
dependsOn:
- db_backup
condition: always()
variables:
db_backup_result: $[ dependencies.db_backup.result ]
steps:
- bash: |
status="failed"
# Access the variables that were set at the job level
if [[ "$(db_backup_result)" == "Succeeded" || "$(db_backup_result)" == "Skipped" ]]; then
status="succeeded"
fi
echo "The final status of the DB Backup stage is: $status"
echo "##vso[task.setvariable variable=stage_status;isOutput=true]$status"
name: set_db_backup_status
displayName: Set Database Backup Status
- stage: notify_stage
displayName: Send Slack Notification
dependsOn:
- db_backup_stage
condition: always()
variables:
set_db_backup_stage_status: $[ stageDependencies.db_backup_stage.set_db_backup_stage_status.outputs['set_db_backup_status.stage_status'] ]
slackWebHook: $(SLACK_WEBHOOK_URL_WORKFLOWS)
jobs:
- job: set_status_job
displayName: Set Status Output
steps:
- bash: |
# Construct the JSON string
JSON_INPUT=$(cat <<EOF
{
"DB Backup": "$(set_db_backup_stage_status)"
}
EOF
)
bash $(System.DefaultWorkingDirectory)/scripts/bash/ado_set_stage_status.sh "$JSON_INPUT"
name: set_status
displayName: Set Slack Message Status
- job: send_message_job
displayName: Send Slack Message
dependsOn: set_status_job
variables:
final_status: $[ dependencies.set_status_job.outputs['set_status.status'] ]
failed_stages: $[ dependencies.set_status_job.outputs['set_status.failedStages'] ]
slackFailureMessage: |
*❌ $(ENVIRONMENT_SHORT) Database Backup _Failed_*
*Failed Action:* $(failed_stages)
*<$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)|View Pipeline Run for details>*
steps:
- checkout: dtos-devops-templates
sparseCheckoutDirectories: scripts
path: templates
- task: PythonScript@0
displayName: 'Send Slack Failure Notification'
condition: eq(variables.final_status, 'failed')
inputs:
scriptSource: 'filePath'
scriptPath: '$(Pipeline.Workspace)/templates/scripts/integrations/slack/SlackIntegrator.py'
arguments: >
--webhook "$(slackWebHook)"
--markdown "$(slackFailureMessage)"