forked from coreos/fedora-coreos-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.groovy
108 lines (98 loc) · 2.94 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
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
import org.yaml.snakeyaml.Yaml;
def shwrap(cmds) {
sh """
set -xeuo pipefail
# https://pagure.io/centos-infra/issue/79
if [ `umask` = 0000 ]; then
umask 0022
fi
${cmds}
"""
}
// Useful when we don't want to show confidential information in logs
def shwrap_quiet(cmds) {
sh """
set +x -euo pipefail
# https://pagure.io/centos-infra/issue/79
if [ `umask` = 0000 ]; then
umask 0022
fi
${cmds}
"""
}
def shwrap_capture(cmds) {
return sh(returnStdout: true, script: """
set -euo pipefail
# https://pagure.io/centos-infra/issue/79
if [ `umask` = 0000 ]; then
umask 0022
fi
${cmds}
""").trim()
}
def shwrap_rc(cmds) {
return sh(returnStatus: true, script: """
set -euo pipefail
# https://pagure.io/centos-infra/issue/79
if [ `umask` = 0000 ]; then
umask 0022
fi
${cmds}
""")
}
def get_annotation(bc, anno) {
def bcYaml = readYaml(text: shwrap_capture("oc get buildconfig ${bc} -n ${env.PROJECT_NAME} -o yaml"))
return bcYaml['metadata']['annotations']["coreos.com/${anno}"]
}
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]
return get_annotation(bc, anno)
}
// This is like fileExists, but actually works inside the Kubernetes container.
def path_exists(path) {
return shwrap_rc("test -e ${path}") == 0
}
// Parse and handle the result of Kola
boolean checkKolaSuccess(dir, currentBuild) {
// archive the image if the tests failed
def report = readJSON file: "${dir}/reports/report.json"
def result = report["result"]
print("kola result: ${result}")
if (result != "PASS") {
if (report["platform"] == "qemu-unpriv") {
shwrap("coreos-assembler compress --compressor xz")
archiveArtifacts "builds/latest/**/*.qcow2.xz"
}
currentBuild.result = 'FAILURE'
return false
}
return true
}
def aws_s3_cp_allow_noent(src, dest) {
// see similar code in `cosa buildprep`
shwrap("""
export AWS_CONFIG_FILE=\${AWS_FCOS_BUILDS_BOT_CONFIG}
python3 -c '
import os, sys, tempfile, botocore, boto3
src = sys.argv[1]
dest = sys.argv[2]
assert src.startswith("s3://")
bucket, key = src[len("s3://"):].split("/", 1)
s3 = boto3.client("s3")
try:
with tempfile.NamedTemporaryFile(mode="wb", dir=os.path.dirname(dest), delete=False) as f:
s3.download_fileobj(bucket, key, f)
f.flush()
os.rename(f.name, dest)
print(f"Downloaded {src} to {dest}")
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] != "404":
raise e
print(f"{src} does not exist")
' '${src}' '${dest}'""")
}
return this