DEV Community

Beatriz R
Beatriz R

Posted on

Integrate ESLint with Jenkins Multibranch Pipeline

A quick overview of ESLint + Jenkins integration, since I haven't seen many examples on internet.


For ESLint & Jenkins integration, we can use Warnings Next Generation Jenkins plugin.

A partial Jenkinsfile example for Multibranch Pipeline project would be:

stage('Install dependencies') {
        steps {
            echo 'Installing dependencies...'
            sh 'rm -rf node_modules package-lock.json && npm install'
        }
}
stage('Build') {
        steps {
            sh 'npm run build'
        }
}
stage ('Static Analysis') {
        steps {
            sh ' ./node_modules/eslint/bin/eslint.js -f checkstyle src > eslint.xml'
        }
        post {
            always {
                recordIssues enabledForFailure: true, aggregatingResults: true, tool: checkStyle(pattern: 'eslint.xml')
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

From plugin documentation on github:

recordIssues step scans for issues in a given set of files (or in the console log) and reports these issues in your build.

This will enable a CheckStyle Warnings menu on your build #, like this:

image


Questions? Suggestions? Please let me know.

Top comments (0)