diff --git a/buildenv/jenkins/common/build.groovy b/buildenv/jenkins/common/build.groovy index 916a0641265..a085a7c4ca2 100644 --- a/buildenv/jenkins/common/build.groovy +++ b/buildenv/jenkins/common/build.groovy @@ -21,6 +21,9 @@ *******************************************************************************/ import groovy.json.JsonSlurper; import groovy.json.JsonOutput; +import java.util.regex.Matcher +import java.util.regex.Pattern + pipelineFunctions = load 'buildenv/jenkins/common/pipeline-functions.groovy' def get_source() { @@ -284,17 +287,23 @@ def checkoutRef (REF) { def build() { stage('Compile') { - def make_target = 'all' + def freemarker_option = FREEMARKER ? "--with-freemarker-jar=${FREEMARKER}" : "" OPENJDK_CLONE_DIR = "${env.WORKSPACE}/${OPENJDK_CLONE_DIR}" withEnv(BUILD_ENV_VARS_LIST) { dir(OPENJDK_CLONE_DIR) { try { - def freemarker_option = FREEMARKER ? "--with-freemarker-jar=${FREEMARKER}" : "" - sh "${BUILD_ENV_CMD} bash configure ${freemarker_option} --with-boot-jdk=${BOOT_JDK} ${EXTRA_CONFIGURE_OPTIONS} && make ${EXTRA_MAKE_OPTIONS} ${make_target}" - } catch (e) { - archive_diagnostics() - throw e + sh "${BUILD_ENV_CMD} bash configure ${freemarker_option} --with-boot-jdk=${BOOT_JDK} ${EXTRA_CONFIGURE_OPTIONS} && ${get_compile_command()}" + } catch (Exception e) { + // last 5000 console output lines + LOG_MAX_LINES = params.LOG_MAX_LINES ? params.LOG_MAX_LINES.toInteger() : 5000 + LOG_LINES = currentBuild.getRawBuild().getLog(LOG_MAX_LINES) + if (match_fail_pattern(LOG_LINES)) { + recompile() + } else { + archive_diagnostics() + throw e + } } } } @@ -306,6 +315,10 @@ def build() { } } +def get_compile_command() { + return "make ${EXTRA_MAKE_OPTIONS} all" +} + def archive_sdk() { stage('Archive') { def buildDir = "build/${RELEASE}/images/" @@ -720,4 +733,49 @@ def build_all() { } } +def match_fail_pattern(outputLines) { + if (!FAIL_PATTERN) { + return false + } + + println("Build failure, searching fail pattern in the last ${outputLines.size()} output lines") + Pattern pattern = Pattern.compile(FAIL_PATTERN) + for (line in outputLines) { + Matcher matcher = pattern.matcher(line) + if (matcher.find()) { + return true + } + } + + println("Fail pattern not found!") + return false +} + +def recompile() { + def maxRetry = 3 + def retryCounter = 0 + def doRetry = true + + while ((maxRetry > retryCounter) && doRetry) { + retryCounter++ + println("Attempt to recompile, retry: ${retryCounter}") + + try { + sh "make clean && ${get_compile_command()}" + doRetry = false + } catch (Exception f) { + // crop console output, search only new output + def newLines = currentBuild.getRawBuild().getLog(LOG_MAX_LINES).minus(LOG_LINES) + // cache log + LOG_LINES.addAll(newLines) + + if (!match_fail_pattern(newLines)) { + //different error + archive_diagnostics() + throw f + } + } + } +} + return this diff --git a/buildenv/jenkins/common/variables-functions.groovy b/buildenv/jenkins/common/variables-functions.groovy index b2c33539e0f..ccc6ac50fbb 100644 --- a/buildenv/jenkins/common/variables-functions.groovy +++ b/buildenv/jenkins/common/variables-functions.groovy @@ -1125,7 +1125,7 @@ def validate_arguments(ARGS) { def printStackTrace(e) { def writer = new StringWriter() e.printStackTrace(new PrintWriter(writer)) - echo e.toString() + echo writer.toString() } /* @@ -1585,6 +1585,8 @@ def set_build_variables_per_node() { } } } + + FAIL_PATTERN = params.FAIL_PATTERN ?: buildspec.getScalarField('fail_pattern', SDK_VERSION) } def check_path(inPath) { diff --git a/buildenv/jenkins/jobs/pipelines/Pipeline_Template.groovy b/buildenv/jenkins/jobs/pipelines/Pipeline_Template.groovy index 0909e24dc00..e065f0999ea 100644 --- a/buildenv/jenkins/jobs/pipelines/Pipeline_Template.groovy +++ b/buildenv/jenkins/jobs/pipelines/Pipeline_Template.groovy @@ -121,6 +121,7 @@ pipelineJob("$JOB_NAME") { } else if (jobType == 'build') { stringParam('NODE') choiceParam('JOB_TYPE', ['build']) + stringParam('FAIL_PATTERN') } } } diff --git a/buildenv/jenkins/variables/defaults.yml b/buildenv/jenkins/variables/defaults.yml index cf132a5d31a..ba659c00459 100644 --- a/buildenv/jenkins/variables/defaults.yml +++ b/buildenv/jenkins/variables/defaults.yml @@ -344,8 +344,6 @@ aarch64_linux: x86-64_windows: extends: ['boot_jdk_default', 'cuda', 'debuginfo', 'openjdk_reference_repo', 'openssl', 'openssl_bundle'] boot_jdk: - location: - all: '/cygdrive/f/Users/jenkins/bootjdks' arch: 'x64' os: 'windows' release: @@ -365,14 +363,13 @@ x86-64_windows: build: 'ci.role.build && hw.arch.x86 && sw.os.windows' build_env: vars: 'PATH+TOOLS=/cygdrive/c/openjdk/LLVM64/bin:/cygdrive/c/openjdk/nasm-2.13.03' + fail_pattern: 'C1083' #========================================# # Windows x86 32bits #========================================# x86-32_windows: extends: ['boot_jdk_default', 'debuginfo', 'openjdk_reference_repo', 'openssl', 'openssl_bundle'] boot_jdk: - location: - all: '/cygdrive/f/Users/jenkins/bootjdks' arch: 'x64' os: 'windows' release: @@ -386,6 +383,7 @@ x86-32_windows: build_env: vars: 8: 'PATH+TOOLS=/cygdrive/c/openjdk/LLVM32/bin:/cygdrive/c/openjdk/nasm-2.13.03' + fail_pattern: 'C1083' #========================================# # Mac x86 64bits #========================================#