Pipeline Job With Parallel Reports Both: Test Result (no failures) Show all failed tests >>>

573 views Asked by At

When I run my pipeline job, I get both a no failures message and a Show all failed test message. My win branch of the parallel had all pass and completed 2nd as windows is slower than lin. My lin branch had one failure.

Test Result (no failures) Show all failed tests >>>

How can I refactor my pipeline to ensure that tests from each branch are processes as a whole?

Pipeline Script

@NonCPS
void emailNotification(def message) {

   emailext attachLog: true, 
   body: """<a href="${env.BUILD_URL}">"${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}</a> """, 
   replyTo: '[email protected]', 
   subject: "${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}: ${message}", 
  to: "..."
}

def problems = []
def branches = [:]

def reportProblem(def message) {
  error " ********* ${message}"
  problems.add(message)
}

@NonCPS
def addArchiveSteps(String platform) {
println "Add Arch ************ ${platform}"
  step([$class: 'ArtifactArchiver', artifacts: "${platform}/**/build/reports/**,**/build/*.log", excludes: null])  
  step([$class: 'JUnitResultArchiver', testResults: "${platform}/**/test-results/*.xml", fingerprint: false])
  junit "${platform}/**/test-results/*.xml"
}

def prepWorkspace(String platform) {
  println "PrepWS Arch ************ ${platform}"

  // Main Checkout
 checkout([$class: 'GitSCM', branches: [[name: '*/master']], browser: [$class: 'GithubWeb', repoUrl: '....]]])

}


echo "***** Prepare Linux Branch"
branches["LinuxBuild"] = {
  node('linx64&&slave')
  {
    timestamps {
      def platform="Linx64"
      try 
      {
        ws("/opt/builds/build-dir/MyPipelineJobWorkspace")
        {

          withEnv(["JAVA_HOME=/opt/tools/Java/jdk1.7.0_79"]){

            prepWorkspace(platform)

            try {
              sh "${platform}/gradle/bin/gradle -p ${platform} clean build -x test --refresh-dependencies"
              sh "${platform}/gradle/bin/gradle -p ${platform} test"
            } catch (Exception e) {
              reportProblem("Failing ${platform} Build due to ${e.message}")
            } finally {
              sh "${platform}/gradle/bin/gradle -p ${platform} jacocoTestReport"
              addArchiveSteps(platform)
            }             
          }

        }
        currentBuild.result = 'SUCCESS'
      } catch (Exception e) {
        reportProblem("Failing ${platform} Build due to ${e.message}")
        currentBuild.result = 'FAILURE'
      }
      finally 
      {
        sh "rm -r /opt/builds/build-dir/MyPipelineJobWorkspace"
      }
    }
  }
}

echo "***** Prepare Windows Branch"
branches["Windows Build"] = {
  node('winx64&&slave')
  {
    timestamps {
      def platform="Winx64"

      try 
      {
        ws("D:\\builds\\build-dir\\MyPipelineJobWorkspace")
        {

          withEnv(["JAVA_HOME=D:\\tools\\Java\\jdk1.7.0_79"]){

            prepWorkspace(platform)

            try {
              bat "${platform}\\gradle\\bin\\gradle -p ${platform} clean build -x test --refresh-dependencies"
              bat "${platform}\\gradle\\bin\\gradle -p ${platform} test"
            } catch (Exception e) {
              reportProblem("Failing ${platform} Build due to ${e.message}")
            } finally {
              bat "${platform}\\gradle\\bin\\gradle -p ${platform} jacocoTestReport"  
              addArchiveSteps(platform)
            }
          }
        }           
        currentBuild.result = 'SUCCESS'
      } catch (Exception e) {
        error "Failing ${platform} Build due to ${e.getMessage()}"
        currentBuild.result = 'FAILURE'
      }
      finally
      {
        bat "rd /s/q D:\\builds\\build-dir\\MyPipelineJobWorkspace"
      }
    }
  }
}

stage name: 'Build', concurrency: 1
echo "***** Execute Branches"
parallel branches

stage name: 'Deploy', concurrency: 1
echo "***** Deploy"

if (problems.size == 0) {
  node('linx64&&slave')
  {
    timestamps {
      try 
      {
        def platform="Linx64"  
        ws('/opt/builds/build-dir/MyPipelineJobWorkspace')
        {
          echo 'Publish'

          withEnv(["JAVA_HOME=/opt/tools/Java/jdk1.7.0_79"]){
            prepWorkspace(platform)

            sh "${platform}/gradle/bin/gradle -p ${platform} clean build publish -x test --refresh-dependencies"

          }
        }
        currentBuild.result = 'SUCCESS'
      } catch (Exception e) {
        currentBuild.result = 'FAILURE'
        reportProblem("Failing Deploy because ${e.message}")
      }
      finally 
      {
        sh "rm -r /opt/builds/build-dir/MyPipelineJobWorkspace"
      }
    }
  }  
} else {
  error "${problems.size()} problems found\n-------------------\n\t"
  error problems.join("\n\t")
}
0

There are 0 answers