forked from coreos/fedora-coreos-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.groovy
72 lines (61 loc) · 1.83 KB
/
utils.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
69
70
71
72
workdir = env.WORKSPACE
def shwrap(cmds) {
sh """
set -xeuo pipefail
cd ${workdir}
${cmds}
"""
}
def shwrap_capture(cmds) {
return sh(returnStdout: true, script: """
set -euo pipefail
cd ${workdir}
${cmds}
""").trim()
}
def shwrap_rc(cmds) {
return sh(returnStatus: true, script: """
set -euo pipefail
cd ${workdir}
${cmds}
""")
}
def get_pipeline_annotation(anno) {
// should probably cache this, but meh... I'd rather
// hide this goop here than in the main pipeline code
def split = env.JOB_NAME.split('/')
def namespace = split[0]
def bc = split[1][namespace.length()+1..-1]
def annopath = "{.metadata.annotations.coreos\\\\.com/${anno}}"
return shwrap_capture(
"oc get buildconfig ${bc} -n ${namespace} -o=jsonpath=${annopath}")
}
// This is like fileExists, but actually works inside the Kubernetes container.
def path_exists(path) {
return shwrap_rc("test -e ${path}") == 0
}
def rsync(from, to) {
def rsync_keypath = "/var/run/secrets/kubernetes.io/duffy-key/duffy.key"
if (!path_exists(rsync_keypath)) {
echo "No ${rsync_keypath} file with rsync key."
echo "Must be operating in dev environment"
echo "Skipping rsync...."
return
}
shwrap("""
# so we don't echo password to the jenkins logs
set +x
RSYNC_PASSWORD=\$(cat ${rsync_keypath})
export RSYNC_PASSWORD=\${RSYNC_PASSWORD:0:13}
set -x
# always add trailing slash for consistent semantics
rsync -ah --stats --delete ${from}/ ${to}
""")
}
def rsync_in(from, to) {
rsync("[email protected]::fedora-coreos/prod/${from}", "${to}")
}
def rsync_out(from, to) {
rsync("${from}", "[email protected]::fedora-coreos/prod/${to}")
}
return this