-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile.purge_cache
39 lines (35 loc) · 1.43 KB
/
Jenkinsfile.purge_cache
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
pipeline {
agent any
environment {
CLOUDFLARE_ZONE_ID = credentials('cloudflare-angular-love-zone-id')
}
stages {
stage('Purge Cache') {
steps {
withCredentials([
usernamePassword(credentialsId: 'cf-workers-creds', usernameVariable: 'CLOUDFLARE_ACCOUNT_ID', passwordVariable: 'CLOUDFLARE_API_TOKEN'),
]) {
script {
def response = sh(script: """
curl -X POST "https://api.cloudflare.com/client/v4/zones/${env.CLOUDFLARE_ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${env.CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"purge_everything": true}'
""", returnStdout: true)
// Check if purge was successful
def jsonResponse = readJSON text: response
if (!jsonResponse.success) {
error "Failed to purge Cloudflare cache: ${jsonResponse.errors}"
}
echo "Successfully purged Cloudflare cache"
}
}
}
}
}
post {
failure {
echo "Failed to purge Cloudflare cache"
}
}
}