-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathargoSync.groovy
68 lines (62 loc) · 2.51 KB
/
argoSync.groovy
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
//
// Author: Hari Sekhon
// Date: 2021-09-01 14:07:59 +0100 (Wed, 01 Sep 2021)
//
// vim:ts=2:sts=2:sw=2:et
//
// https://github.com/HariSekhon/Jenkins
//
// License: see accompanying Hari Sekhon LICENSE file
//
// If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
//
// https://www.linkedin.com/in/HariSekhon
//
// ========================================================================== //
// A r g o C D S y n c
// ========================================================================== //
// Forked from argoDeploy() function to allow app deployment parallelization
// by pre-calling argoSync for more than one app before argoDeploy() which waits on each app
// Required Environment Variables to be set in environment{} section of Jenkinsfile, see top level Jenkinsfile template
//
// ARGOCD_SERVER
// ARGOCD_AUTH_TOKEN
//
// The ArgoCD app must be passed as the first argument
// ArgoCD sync usually takes 20-60 secs even for a large app full of different deployments and many cronjobs,
// so 5 minute timeout default should be more than enough for all sane use cases
def call (app, timeoutMinutes=5) {
String label = "ArgoCD Sync - App: '$app'"
int timeoutSeconds = timeoutMinutes * 60 - 10
echo "Acquiring ArgoCD Lock: $label"
lock (resource: label, inversePrecedence: true) {
// XXX: prevents calling in a parallel stage otherwise you'll get this error:
//
// "Using a milestone step inside parallel is not allowed"
//
milestone ordinal: null, label: "Milestone: $label"
// let caller decide if wrapping this in a container('argocd') or using downloadArgo.groovy to save RAM
//container ('argocd') {
timeout (time: timeoutMinutes, unit: 'MINUTES') {
waitUntil (initialRecurrencePeriod: 5000) {
withEnv (["APP=$app", "TIMEOUT_SECONDS=$timeoutSeconds"]) {
// Blue Ocean doesn't hide script with this label, even though it does for argoDeploy(), so echo explicitly
echo "$label"
script {
int exitCode = sh (
label: "$label",
returnStatus: true,
script: '''
set -eux
argocd app sync "$APP" --grpc-web --force --timeout "$TIMEOUT_SECONDS"
'''
)
// convert exitCode boolean for waitUntil()
exitCode == 0
}
}
}
}
//}
}
}