Improve jenkins log usability
vars/helmTeardown.groovy
------------------------
o Changed sh() into sh(label, script), self documenting and label cannot
get lost in streams like println() output has.
o Remove local string vars (banner,msg) and inline status messages
since they are now displaying loop iteration content.
o Also added set +x in the first loop, status messages display progress
more clearly than echo(ing) the shell command.
Change-Id: I51354a2b0c3aa2431638b602e9b31c6c0402cc87
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
diff --git a/vars/helmTeardown.groovy b/vars/helmTeardown.groovy
index 0d7bb1c..9be801e 100644
--- a/vars/helmTeardown.groovy
+++ b/vars/helmTeardown.groovy
@@ -24,35 +24,34 @@
def call(List namespaces = ['default'], List excludes = ['docker-registry']) {
String spaces = namespaces.join(', ')
- String msg = "Tearing down charts in namespaces: ${spaces}."
- println(msg)
+ println("Tearing down charts in namespaces: ${spaces}.")
def exc = excludes.join('|')
for (int i = 0; i < namespaces.size(); i++) {
- // sh() and groovy String vars do not play well together
def n = namespaces[i]
-
- sh(label : "Tearing down charts in namespaces: ${n}.",
+ sh(label : "Tearing down chart in namespace ${n}",
script : """
+ set +x
for hchart in \$(helm list --all -n ${n} -q | grep -E -v '${exc}');
do
echo "Purging chart: \${hchart}"
helm delete -n ${n} "\${hchart}"
done
- """)
+""")
}
- println "Waiting for pods to be removed from namespaces: ${namespaces.join(', ')}."
+ banner = "Waiting for pods to be removed from namespaces: ${spaces}"
for (int i = 0; i < namespaces.size(); i++) {
def n = namespaces[i]
- sh """
+ sh(label : "Waiting for pod removal in namespace ${n}",
+ script : """
set +x
PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
while [[ \$PODS != 0 ]]; do
sleep 5
PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
done
- """
+""")
}
}