Skip to content

Commit 5a68cf1

Browse files
authored
jenkins: linter refactor & fix for 6.x (#1349)
* break down directive into single commands * don't fail if `lint-md-build` doesn't exist * replace `sed` with `awk` PR-URL: #1349 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Matheus Marchini <matheus@sthima.com>
1 parent 126d197 commit 5a68cf1

1 file changed

Lines changed: 38 additions & 24 deletions

File tree

jenkins/pipelines/node-linter.jenkinsfile

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ pipeline {
88
string(name: 'GIT_REMOTE_REF', defaultValue: 'refs/heads/master', description: 'The remote portion of the Git refspec to fetch and test')
99
string(name: 'REBASE_ONTO', defaultValue: '', description: 'Optionally, rebase onto the given ref before testing. Leave blank to skip rebasing.')
1010
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.')
11-
choice(name: 'GIT_ORIGIN_SCHEME', choices: "https://github.com/\ngit@github.com:", description: '')
12-
string(name: 'POST_STATUS_TO_PR', defaultValue: '', description: 'Posts build status updates to a nodejs/node PR.')
1311
string(name: 'CONFIG_FLAGS', defaultValue: '', description: 'Add arguments to ./configure.')
1412
}
1513

@@ -23,33 +21,40 @@ pipeline {
2321
]],
2422
userRemoteConfigs: [[
2523
credentialsId: "96d5f81c-e9ad-45f7-ba5d-bc8107c0ae2c",
26-
url: "${params.GIT_ORIGIN_SCHEME}${params.GITHUB_ORG}/${params.REPO_NAME}",
24+
url: "git@github.com:${params.GITHUB_ORG}/${params.REPO_NAME}",
2725
refspec: "+refs/heads/*:refs/remotes/origin/* +${params.GIT_REMOTE_REF}:refs/remotes/origin/_jenkins_local_branch"
2826
]]
2927
])
3028
}
3129
}
3230

33-
stage('Preflight') {
31+
stage('Pre-flight') {
3432
steps {
35-
sh "curl https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe"
33+
sh "curl -L -s https://raw.githubusercontent.com/nodejs/build/master/jenkins/scripts/node-test-commit-pre.sh -s | bash -xe"
3634
sendBuildStatus("pending", env)
35+
checkMake()
36+
// Make sure we have a node binary in the path
37+
sh 'node --version'
3738
}
3839
}
3940

41+
stage('Build linting tools') {
42+
steps {
43+
// Calling with `returnStatus` suppresses automatic failures
44+
sh(script: "${env.MAKE} lint-md-build", returnStatus: true)
45+
}
46+
}
47+
4048
stage('Run tests') {
4149
steps {
42-
checkMake()
43-
checkSed()
44-
sh """
45-
# this job does not build node, so we symlink the system's node
46-
which node #&& ln -s ${sh(script: "which node", returnStdout: true).trim()}
47-
node --version
48-
49-
${env.MAKE} lint-md-build || true
50-
# If lint-ci fails, print all the interesting lines to the console.
51-
${env.MAKE} lint-ci || { cat test-eslint.tap | grep -v '^ok\\|^TAP version 13\\|^1\\.\\.' | ${env.SED} '/^/\\s*\$/d' && exit 1; }
52-
"""
50+
script {
51+
// this job does not build node, so we use the system's node
52+
def ret = sh(script: "NODE=node ${env.MAKE} lint-ci", returnStatus: true)
53+
if (ret != 0) {
54+
echo(extractErrors())
55+
error('lint failed - open above section for details')
56+
}
57+
}
5358
}
5459
}
5560
}
@@ -65,6 +70,23 @@ pipeline {
6570
}
6671
}
6772

73+
def extractErrors() {
74+
def tap = readFile('test-eslint.tap')
75+
tap = tap.replaceAll('(?m)^ok.*', '')
76+
tap = tap.replaceAll('(?m)^TAP version 13.*', '')
77+
tap = tap.replaceAll('(?m)^1\\.\\..*', '')
78+
tap = tap.replaceAll('(?m)^\\s+$', '')
79+
return tap
80+
}
81+
82+
def tap2JUnit() {
83+
fileOperations([folderCreateOperation('out/junit')])
84+
def status = sh(returnStatus: true, script: 'tap2junit -i test-eslint.tap -o out/junit/test-eslint.xml')
85+
if (status == 0) {
86+
junit(allowEmptyResults: true, testResults: 'out/junit/*.xml')
87+
}
88+
}
89+
6890
def checkMake() {
6991
def status = sh(returnStatus: true, script: "which gmake")
7092
if (status != 0) {
@@ -74,14 +96,6 @@ def checkMake() {
7496
}
7597
}
7698

77-
def checkSed() {
78-
def status = sh(returnStatus: true, script: "which gsed")
79-
if (status != 0) {
80-
env.SED = 'sed'
81-
} else {
82-
env.SED = 'gsed'
83-
}
84-
}
8599

86100
def sendBuildStatus(status, env) {
87101
build job: 'post-build-status-update', parameters: [

0 commit comments

Comments
 (0)