Catch failures in salt runs during update

Fixes: PROD-21566 (PROD:21566)

Change-Id: Ifcebd6fadd9361f252b540bd5e246644e37c70e9
diff --git a/update-package.groovy b/update-package.groovy
index 790e2ac..c3882fe 100644
--- a/update-package.groovy
+++ b/update-package.groovy
@@ -91,6 +91,11 @@
             stage('Apply package upgrades on sample') {
                 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, packages, commandKwargs)
                 salt.printSaltCommandResult(out)
+                for(value in out.get("return")[0].values()){
+                    if (value.containsKey('result') && value.result == false) {
+                        throw new Exception("The package upgrade on sample node has failed. Please check the Salt run result above for more information.")
+                    }
+                }
             }
 
             stage('Confirm package upgrades on all nodes') {
@@ -102,6 +107,12 @@
             stage('Apply package upgrades on all nodes') {
                 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, packages, commandKwargs)
                 salt.printSaltCommandResult(out)
+                for(value in out.get("return")[0].values()){
+                    if (value.containsKey('result') && value.result == false) {
+                        throw new Exception("The package upgrade on sample node has failed. Please check the Salt run result above for more information.")
+                    }
+                }
+                common.warningMsg("Pipeline has finished successfully, but please, check if any packages have been kept back.")
             }
 
         } catch (Throwable e) {