Report results in proper order

Closes-Bug: #PROD-30631
Change-Id: Ia9083256dbb4c2d94100fecf2b1019768f2ec396
diff --git a/jobs/pipelines/swarm-testrail-report.groovy b/jobs/pipelines/swarm-testrail-report.groovy
index 38a7968..e754936 100644
--- a/jobs/pipelines/swarm-testrail-report.groovy
+++ b/jobs/pipelines/swarm-testrail-report.groovy
@@ -33,6 +33,7 @@
     }
     dir("${PARENT_WORKSPACE}") {
         def description = ''
+        def exception_message = ''
         try {
 
             if (env.TCP_QA_REFS) {
@@ -47,7 +48,6 @@
             def testrail_name_template = ''
             def reporter_extra_options = []
 
-            def report_result = ''
             def report_url = ''
 
             //  deployment_report_name = "deployment_${ENV_NAME}.xml"
@@ -83,14 +83,15 @@
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                       "--testrail-case-section-name \'All\'",
                     ]
-                    report_result = shared.upload_results_to_testrail(deployment_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(deployment_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -104,14 +105,15 @@
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                       "--testrail-case-section-name \'All\'",
                     ]
-                    report_result = shared.upload_results_to_testrail(tcpqa_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(tcpqa_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -120,14 +122,15 @@
                     testSuiteName = env.TEMPEST_TEST_SUITE_NAME
                     methodname = "{classname}.{methodname}"
                     testrail_name_template = "{title}"
-                    report_result = shared.upload_results_to_testrail(tempest_report_name, testSuiteName, methodname, testrail_name_template)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(tempest_report_name, testSuiteName, methodname, testrail_name_template)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -146,14 +149,15 @@
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                       "--testrail-case-section-name \'Conformance\'",
                     ]
-                    report_result = shared.upload_results_to_testrail(k8s_conformance_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(k8s_conformance_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -168,14 +172,15 @@
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                       "--testrail-case-section-name \'Conformance\'",
                     ]
-                    report_result = shared.upload_results_to_testrail(k8s_conformance_virtlet_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(k8s_conformance_virtlet_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -184,14 +189,15 @@
                     testSuiteName = "LMA2.0_Automated"
                     methodname = "{methodname}"
                     testrail_name_template = "{title}"
-                    report_result = shared.upload_results_to_testrail(stacklight_report_name, testSuiteName, methodname, testrail_name_template)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(stacklight_report_name, testSuiteName, methodname, testrail_name_template)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
@@ -206,17 +212,23 @@
                       "--testrail-case-custom-fields {\\\"custom_qa_team\\\":\\\"9\\\"}",
                       "--testrail-case-section-name \'All\'",
                     ]
-                    report_result = shared.upload_results_to_testrail(cvp_sanity_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
-                    common.printMsg(report_result, "blue")
-                    report_url = report_result.split("\n").each {
+                    ret = shared.upload_results_to_testrail(cvp_sanity_report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options)
+                    common.printMsg(ret.stdout, "blue")
+                    report_url = ret.stdout.split("\n").each {
                         if (it.contains("[TestRun URL]")) {
                             common.printMsg("Found report URL: " + it.trim().split().last(), "blue")
                             description += "<a href=" + it.trim().split().last() + ">${testSuiteName}</a><br>"
                         }
                     }
+                    exception_message += ret.exception
                 }
             }
 
+            // Check if there were any exceptions during reporting
+            if (exception_message) {
+                throw new Exception(exception_message)
+            }
+
         } catch (e) {
             common.printMsg("Job is failed", "purple")
             throw e