From 73281006b183cfffba7edfa34e822ad574cca3e6 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 19 Nov 2021 14:26:43 -0300 Subject: [PATCH] Jenkins: Add new method of extracting the current HEAD commit --- .ci/Jenkinsfile | 60 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 28ef5e005..0d6d1e987 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -120,19 +120,39 @@ pipeline { steps { script { - /* Run a dummy git clone on any node to try and save the latest commit regardless of executor status. - This avoids a timing issue where HEAD changes between polling and the nodes being available below. - I talked to a few people, and we reached the conclusion that reading the polled commit from within - the pipeline is not really possible (maybe short of switching to a multi-branch pipeline), so we - have to live with this hack, which shortens but doesn't fully eliminate the timing issue's window. */ - node { - /* Ignore exceptions as this is not really critical. */ - try { - gitClone() - } catch (e) {} - try { - cleanWs() - } catch (e) {} + /* Cursed hack to extract the current HEAD commit from this build's + git polling log. This avoids a timing issue where HEAD changes + between polling and the nodes being available below. */ + if (env.GIT_COMMIT == null) { + /* This must run on the master node to read the polling log. */ + node('master') { + /* Ignore exceptions as this is not really critical. */ + try { + /* Switch to this build's directory. */ + dir("${env.JENKINS_HOME}/jobs/${env.JOB_NAME}/builds/${env.BUILD_NUMBER}") { + /* Parse polling log. */ + def pollingLog = readFile file: 'polling.log' + def match = pollingLog =~ /Latest remote head revision on [^ ]+ is: ([a-zA-Z0-9]+)/ + if (match && match[0]) { + env.GIT_COMMIT = match[0][1] + println "[-] Read git tag [${env.GIT_COMMIT}] from polling log" + } + } + } catch (e) {} + } + + /* If the polling log parsing fails, run a dummy git clone on any node. */ + if (env.GIT_COMMIT == null) { + node { + /* Ignore exceptions again as this is not really critical. */ + try { + gitClone() + } catch (e) {} + try { + cleanWs() + } catch (e) {} + } + } } /* Create source tarball. */ @@ -187,14 +207,10 @@ pipeline { removeDir('output') /* Switch to output directory. */ - dir('output') { + dir("output/${dynarecNames[dynarec]}/$os - ${archNames[arch]}") { + /* Run build process. */ def packageName = "${env.JOB_BASE_NAME}${dynarecSlugs[dynarec]}${presetSlugs[preset]}-$os-$arch-b${env.BUILD_NUMBER}" - dir(dynarecNames[dynarec]) { - dir("$os - ${archNames[arch]}") { - /* Run build process. */ - runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} -D \"BUILD_TYPE=$BUILD_TYPE\" -D \"EMU_BUILD=build ${env.BUILD_NUMBER}\" -D \"EMU_BUILD_NUM=${env.BUILD_NUMBER}\"") - } - } + runBuild("-b \"$packageName\" \"$arch\" ${presetFlags[preset]} ${dynarecFlags[dynarec]} -D \"BUILD_TYPE=$BUILD_TYPE\" -D \"EMU_BUILD=build ${env.BUILD_NUMBER}\" -D \"EMU_BUILD_NUM=${env.BUILD_NUMBER}\"") /* Archive resulting artifacts. */ archiveArtifacts artifacts: "**/**/$packageName*" @@ -223,12 +239,14 @@ pipeline { post { always { script { + /* Mark build as failed if any step has failed. */ if (anyFailure) { println "[!] Failing build because a build stage failed" currentBuild.result = 'FAILURE' } - if (!env.JOB_BASE_NAME.contains("TestBuildPleaseIgnore")) { + /* Send out build notifications. */ + if (!env.JOB_BASE_NAME.contains('TestBuildPleaseIgnore')) { try { /* Notify Discord. */ def result = currentBuild.currentResult.toLowerCase()