chore(ci)_: simplify Jenkinsfile for tests, fix params (#5136)

Because most of those functions just obscure what's happening.
Also formatting.

Also, it appears Jenkins sets `params` on first run, but not `env`
variables from those `params`.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2024-05-08 21:04:15 +02:00 committed by GitHub
parent db0cc10a73
commit a97f1bb681
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 31 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.8.10' library 'status-jenkins-lib@v1.8.15'
pipeline { pipeline {
agent { label 'linux && x86_64 && nix-2.14' } agent { label 'linux && x86_64 && nix-2.14' }
@ -17,22 +17,22 @@ pipeline {
) )
booleanParam( booleanParam(
name: 'UNIT_TEST_FAILFAST', name: 'UNIT_TEST_FAILFAST',
defaultValue: getDefaultUnitTestFailfast(), defaultValue: !isTestNightlyJob(),
description: 'Should the job fail fast on first test failure?' description: 'Should the job fail fast on first test failure?'
) )
booleanParam( booleanParam(
name: 'UNIT_TEST_RERUN_FAILS', name: 'UNIT_TEST_RERUN_FAILS',
defaultValue: getDefaultUnitTestRerunFails(), defaultValue: !isTestNightlyJob(),
description: 'Should the job rerun failed tests?' description: 'Should the job rerun failed tests?'
) )
booleanParam( booleanParam(
name: 'UNIT_TEST_USE_DEVELOPMENT_LOGGER', name: 'UNIT_TEST_USE_DEVELOPMENT_LOGGER',
defaultValue: getDefaultUnitTestUseDevelopmentLogger(), defaultValue: !isTestNightlyJob(),
description: 'Should the job use detailed logging for tests, potentially generating large logs?' description: 'Should the job use detailed logging for tests, potentially generating large logs?'
) )
booleanParam( booleanParam(
name: 'UNIT_TEST_REPORT_CODECLIMATE', name: 'UNIT_TEST_REPORT_CODECLIMATE',
defaultValue: getDefaultUnitTestReportCodeClimate(), defaultValue: !isTestNightlyJob(),
description: 'Should the job report test coverage to CodeClimate?' description: 'Should the job report test coverage to CodeClimate?'
) )
} }
@ -59,6 +59,12 @@ pipeline {
GOCACHE = "${WORKSPACE_TMP}/gocache" GOCACHE = "${WORKSPACE_TMP}/gocache"
PATH = "${PATH}:${GOPATH}/bin" PATH = "${PATH}:${GOPATH}/bin"
REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go" REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go"
/* Hack-fix for params not being set in env on first job run. */
UNIT_TEST_FAILFAST = "${params.UNIT_TEST_FAILFAST}"
UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}"
UNIT_TEST_USE_DEVELOPMENT_LOGGER = "${params.UNIT_TEST_USE_DEVELOPMENT_LOGGER}"
UNIT_TEST_REPORT_CODECLIMATE = "${params.UNIT_TEST_REPORT_CODECLIMATE}"
} }
stages { stages {
@ -136,26 +142,27 @@ pipeline {
post { post {
always { always {
script { env.PKG_URL = "${currentBuild.absoluteUrl}/consoleText" }
script { script {
if (isTestNightlyJob()) { env.PKG_URL = "${currentBuild.absoluteUrl}/consoleText"
archiveArtifacts artifacts: '**/report_*.xml, **/test_*.log'
if (isTestNightlyJob()) {
archiveArtifacts('**/report_*.xml, **/test_*.log')
def totalSize = sh(script: "find . -name 'report_*.xml' | xargs wc -c | tail -n1 | awk '{print \$1}'", returnStdout: true).trim() def totalSize = sh(script: "find . -name 'report_*.xml' | xargs wc -c | tail -n1 | awk '{print \$1}'", returnStdout: true).trim()
echo "Total size of all report_*.xml files: ${totalSize} bytes" println("Total size of all report_*.xml files: ${totalSize} bytes.")
} }
if (params.UNIT_TEST_RERUN_FAILS) { if (params.UNIT_TEST_RERUN_FAILS) {
def rerunReports = findFiles(glob: '**/report_rerun_fails_*.txt') def rerunReports = findFiles(glob: '**/report_rerun_fails_*.txt')
if (rerunReports.length > 0) { if (rerunReports.length > 0) {
archiveArtifacts artifacts: '**/report_rerun_fails_*.txt' archiveArtifacts('**/report_rerun_fails_*.txt')
} }
} }
} junit(
junit testResults: '**/report_*.xml', testResults: '**/report_*.xml',
skipOldReports: true, skipOldReports: true,
skipPublishingChecks: true, skipPublishingChecks: true,
skipMarkingBuildUnstable: true skipMarkingBuildUnstable: true
publishHTML target: [ )
publishHTML(target: [
allowMissing: true, allowMissing: true,
alwaysLinkToLastBuild: true, alwaysLinkToLastBuild: true,
keepAll: true, keepAll: true,
@ -163,7 +170,8 @@ pipeline {
reportFiles: 'test_stats.txt', reportFiles: 'test_stats.txt',
reportName: 'Reports', reportName: 'Reports',
reportTitles: 'Test Stats' reportTitles: 'Test Stats'
] ])
}
} }
success { script { github.notifyPR(true) } } success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } } failure { script { github.notifyPR(false) } }
@ -178,12 +186,4 @@ def isTestNightlyJob() { env.JOB_BASE_NAME == 'tests-nightly' }
def getDefaultUnitTestCount() { isTestNightlyJob() ? '20' : '1' } def getDefaultUnitTestCount() { isTestNightlyJob() ? '20' : '1' }
def getDefaultUnitTestRerunFails() { isTestNightlyJob() ? false : true }
def getDefaultUnitTestUseDevelopmentLogger() { isTestNightlyJob() ? false : true }
def getDefaultUnitTestReportCodeClimate() { isTestNightlyJob() ? false : true }
def getDefaultUnitTestFailfast() { isTestNightlyJob() ? false : true }
def getDefaultTimeout() { isTestNightlyJob() ? 5*60 : 50 } def getDefaultTimeout() { isTestNightlyJob() ? 5*60 : 50 }