当我运行管道作业时,我同时收到无失败消息和显示所有失败的测试消息。并行的win分支全部通过并完成第2,因为窗口比林慢。我林分支失败了。
Test Result (no failures)
Show all failed tests >>>
如何重构我的管道以确保每个分支的测试都是整个过程?
管道脚本
@NonCPS
void emailNotification(def message) {
emailext attachLog: true,
body: """<a href="${env.BUILD_URL}">"${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}</a> """,
replyTo: 'build@mydomain.com',
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")
}