Fix checking return code

Change-Id: I8263a2f466310778400668a50fe04c10bd31df70
diff --git a/cicd-lab-pipeline.groovy b/cicd-lab-pipeline.groovy
index 82118d1..5433945 100644
--- a/cicd-lab-pipeline.groovy
+++ b/cicd-lab-pipeline.groovy
@@ -102,7 +102,7 @@
         salt.enforceState(saltMaster, 'ci01*', 'glusterfs.server.setup', true)
         sleep(5)
         salt.enforceState(saltMaster, 'I@glusterfs:client', 'glusterfs.client', true)
-        print salt.cmdRun(saltMaster, 'I@glusterfs:client', 'mount|grep fuse.glusterfs')
+        print salt.cmdRun(saltMaster, 'I@glusterfs:client', 'mount|grep fuse.glusterfs || echo "Command failed"')
     }
 
     stage("Deploy GlusterFS") {
@@ -124,13 +124,22 @@
 
         // XXX: Hack to fix dependency of gerrit on mysql
         print salt.cmdRun(saltMaster, 'I@docker:swarm:role:master', "docker service rm gerrit; rm -rf /srv/volumes/gerrit/*")
-        sleep(5)
+        sleep(10)
         print salt.cmdRun(saltMaster, 'I@docker:swarm:role:master', "apt-get install -y mysql-client; mysql -ppassword -h172.16.10.254 -e'drop database gerrit;create database gerrit;'")
         salt.enforceState(saltMaster, 'I@docker:swarm:role:master', 'docker.client')
         // ---- cut here (end of hack) ----
 
         retry(30) {
-            print salt.cmdRun(saltMaster, 'I@docker:swarm:role:master', """/bin/bash -c '! docker service ls | grep -E "0/[0-9]+"'""")
+            out = salt.cmdRun(saltMaster, 'I@docker:swarm:role:master', """/bin/bash -c 'docker service ls | grep -E "0/[0-9]+"' && echo 'Some services are not running'""")
+            for (entry in out['return']) {
+                for (node in entry) {
+                    if (node.value =~ /Some services are not running/) {
+                        throw new Exception("$node.key: $node.value)
+                    } else {
+                        print out
+                    }
+                }
+            }
             sleep(10)
         }
     }