Fix reporting for flaky builds in Jenkinsfile

The verification pipeline was not properly reporting the results of
builds that were suspect to being flaky. This happened, because the
build did not save the results in a variable, if the propagate option
was used, which had to be done for the pipeline plugin's retry command
to work.

Instead of using the retry-command provided by the pipeline plugin,
the Jenkinsfile implements this behaviour manually.

Bug: Issue 11927
Change-Id: I419a20f69cabc4c54d7f57fd04ad354563eafd71
diff --git a/Jenkinsfile b/Jenkinsfile
index ebf2136..e09b0f0 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -154,18 +154,19 @@
 }
 
 def prepareBuildsForMode(buildName, mode="reviewdb", retryTimes = 1) {
-    def propagate = retryTimes == 1 ? false : true
     return {
         stage("${buildName}/${mode}") {
-            catchError{
-                retry(retryTimes){
-                    def slaveBuild = build job: "${buildName}", parameters: [
+            def slaveBuild = null
+            for (int i = 1; i <= retryTimes; i++) {
+                try {
+                    slaveBuild = build job: "${buildName}", parameters: [
                         string(name: 'REFSPEC', value: Change.ref),
                         string(name: 'BRANCH', value: Change.sha1),
                         string(name: 'CHANGE_URL', value: Change.url),
                         string(name: 'MODE', value: mode),
                         string(name: 'TARGET_BRANCH', value: Change.branch)
-                    ], propagate: propagate
+                    ], propagate: false
+                } finally {
                     if (buildName == "Gerrit-codestyle"){
                         Builds.codeStyle = new Build(
                             slaveBuild.getAbsoluteUrl(), slaveBuild.getResult())
@@ -173,6 +174,9 @@
                         Builds.verification[mode] = new Build(
                             slaveBuild.getAbsoluteUrl(), slaveBuild.getResult())
                     }
+                    if (slaveBuild.getResult() == "SUCCESS") {
+                        break
+                    }
                 }
             }
         }