Fix testrail report for deployment cases

Change-Id: Ic57cf7288f0c0e519dbe07a68625648c5c29d51c
diff --git a/jobs/pipelines/swarm-testrail-report.groovy b/jobs/pipelines/swarm-testrail-report.groovy
index df437b3..7d2ce53 100644
--- a/jobs/pipelines/swarm-testrail-report.groovy
+++ b/jobs/pipelines/swarm-testrail-report.groovy
@@ -37,6 +37,10 @@
             def testrail_name_template = ''
             def reporter_extra_options = []
 
+            //stage("Archive all xml reports") {
+            //    archiveArtifacts artifacts: "${PARENT_WORKSPACE}/*.xml"
+            //}
+
             stage("Deployment report") {
                 report_name = "deployment_${ENV_NAME}.xml"
                 testSuiteName = "[MCP] Integration automation"
diff --git a/src/com/mirantis/system_qa/SharedPipeline.groovy b/src/com/mirantis/system_qa/SharedPipeline.groovy
index 7aee6fd..123a667 100644
--- a/src/com/mirantis/system_qa/SharedPipeline.groovy
+++ b/src/com/mirantis/system_qa/SharedPipeline.groovy
@@ -81,8 +81,10 @@
 
             def String junit_report_xml = readFile("${junit_report_filename}")
             def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
+            def String junit_report_xml_headless = junit_report_xml_pretty.replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>","");
+            def String junit_report_xml_filtered = junit_report_xml_headless.replaceAll("<","&lt;").replaceAll(">", "&gt;")
             def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
-            throw new Exception(msg + junit_report_xml_pretty)
+            throw new Exception(msg + junit_report_xml_filtered)
         } else {
             throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
         }
@@ -365,8 +367,7 @@
     // <filename> is name of the XML report file that will be created
     // <status> is one of the 'success', 'skipped', 'failure' or 'error'
     // 'error' status is assumed as 'Blocker' in TestRail reporter
-    run_cmd("""\
-cat << \'EOF\' > ${filename}
+    def script = """\
 <?xml version=\"1.0\" encoding=\"utf-8\"?>
   <testsuite>
     <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
@@ -375,8 +376,8 @@
       <system-err>${stderr}</system-err>
     </testcase>
   </testsuite>
-EOF
-""")
+"""
+    writeFile(file: filename, text: script, encoding: "UTF-8")
 }
 
 def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
@@ -407,7 +408,7 @@
   def script = """
     . ${venvPath}/bin/activate
     set -ex
-    report_xml=\$(find \$(pwd) -name "${report_name}")
+    report_xml=\$(find ${PARENT_WORKSPACE} -name "${report_name}")
     if [ -n "\${report_xml}" ]; then
         report ${reporterOptions.join(' ')} \${report_xml}
     fi
@@ -430,7 +431,7 @@
     def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
     def classname = "Deploy"
     def name = "deployment_${ENV_NAME}"
-    def filename = "\$(pwd)/${name}.xml"
+    def filename = "${name}.xml"
     def status = STATUS_MAP[result ?: 'FAILURE']   // currentBuild.result *must* be set at the finish of the try/catch
     create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
 }