diff --git a/jenkins/pipelines/node-linter.jenkinsfile b/jenkins/pipelines/node-linter.jenkinsfile index 69de9f336..fdd9fdd6f 100644 --- a/jenkins/pipelines/node-linter.jenkinsfile +++ b/jenkins/pipelines/node-linter.jenkinsfile @@ -8,8 +8,6 @@ pipeline { string(name: 'GIT_REMOTE_REF', defaultValue: 'refs/heads/master', description: 'The remote portion of the Git refspec to fetch and test') string(name: 'REBASE_ONTO', defaultValue: '', description: 'Optionally, rebase onto the given ref before testing. Leave blank to skip rebasing.') string(name: 'POST_REBASE_SHA1_CHECK', defaultValue: '', description: 'After rebasing, check that the resulting commit sha1 matches the given one. If left blank, no check is performed.') - choice(name: 'GIT_ORIGIN_SCHEME', choices: "https://github.com/\ngit@github.com:", description: '') - string(name: 'POST_STATUS_TO_PR', defaultValue: '', description: 'Posts build status updates to a nodejs/node PR.') string(name: 'CONFIG_FLAGS', defaultValue: '', description: 'Add arguments to ./configure.') } @@ -23,33 +21,40 @@ pipeline { ]], userRemoteConfigs: [[ credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c", - url: "${params.GIT_ORIGIN_SCHEME}${params.GITHUB_ORG}/${params.REPO_NAME}", + url: "git@github.com:${params.GITHUB_ORG}/${params.REPO_NAME}", refspec: "+refs/heads/*:refs/remotes/origin/* +${params.GIT_REMOTE_REF}:refs/remotes/origin/_jenkins_local_branch" ]] ]) } } - stage('Preflight') { + stage('Pre-flight') { steps { - sh "curl https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe" + sh "curl -L -s https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe" sendBuildStatus("pending", env) + checkMake() + // Make sure we have a node binary in the path + sh 'node --version' } } + stage('Build linting tools') { + steps { + // Calling with `returnStatus` suppresses automatic failures + sh(script: "${env.MAKE} lint-md-build", returnStatus: true) + } + } + stage('Run tests') { steps { - checkMake() - checkSed() - sh """ - # this job does not build node, so we symlink the system's node - which node #&& ln -s ${sh(script: "which node", returnStdout: true).trim()} - node --version - - ${env.MAKE} lint-md-build || true - # If lint-ci fails, print all the interesting lines to the console. - ${env.MAKE} lint-ci || { cat test-eslint.tap | grep -v '^ok\\|^TAP version 13\\|^1\\.\\.' | ${env.SED} '/^/\\s*\$/d' && exit 1; } - """ + script { + // this job does not build node, so we use the system's node + def ret = sh(script: "NODE=node ${env.MAKE} lint-ci", returnStatus: true) + if (ret != 0) { + echo(extractErrors()) + error('lint failed - open above section for details') + } + } } } } @@ -65,6 +70,23 @@ pipeline { } } +def extractErrors() { + def tap = readFile('test-eslint.tap') + tap = tap.replaceAll('(?m)^ok.*', '') + tap = tap.replaceAll('(?m)^TAP version 13.*', '') + tap = tap.replaceAll('(?m)^1\\.\\..*', '') + tap = tap.replaceAll('(?m)^\\s+$', '') + return tap +} + +def tap2JUnit() { + fileOperations([folderCreateOperation('out/junit')]) + def status = sh(returnStatus: true, script: 'tap2junit -i test-eslint.tap -o out/junit/test-eslint.xml') + if (status == 0) { + junit(allowEmptyResults: true, testResults: 'out/junit/*.xml') + } +} + def checkMake() { def status = sh(returnStatus: true, script: "which gmake") if (status != 0) { @@ -74,14 +96,6 @@ def checkMake() { } } -def checkSed() { - def status = sh(returnStatus: true, script: "which gsed") - if (status != 0) { - env.SED = 'sed' - } else { - env.SED = 'gsed' - } -} def sendBuildStatus(status, env) { build job: 'post-build-status-update', parameters: [