npm-groovy-lint inspired cleanups
Review feedback:
- Display target namespace in sh(label) mesage string.
- Name visible in display of helm list -n {name} output but be explicit for logging.
- Early termination may inhibit command display.
Change-Id: I0dadb58ad98ebeb9d793799055a31c69ee699eb8
diff --git a/vars/helmTeardown.groovy b/vars/helmTeardown.groovy
index e6f36ac..81fc0aa 100644
--- a/vars/helmTeardown.groovy
+++ b/vars/helmTeardown.groovy
@@ -15,24 +15,35 @@
// limitations under the License.
// -----------------------------------------------------------------------
+/* -----------------------------------------------------------------------
+groovylint-disable NoDef, VariableTypeRequired
+Reason: jenkins.sh() and groovy String do not play nicely together.
+ cast(String) => java.lang.String not supported natively.
+* -----------------------------------------------------------------------
+*/
+
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: ${namespaces.join(', ')}."
-
- def exc = excludes.join("|")
- for(int i = 0;i<namespaces.size();i++) {
+ 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 """
+
+ sh(label : "Tearing down charts in namespaces: ${n}.",
+ script : """
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(', ')}."
- for(int i = 0;i<namespaces.size();i++) {
+ for (int i = 0; i < namespaces.size(); i++) {
def n = namespaces[i]
sh """
set +x