shelljenkinsshellcheck

Record shellcheck findings in Jenkins


I'm looking for a way to record violation findings of shellcheck in my Jenkins Pipeline script. I was not able to find something so far. For other tools (Java, Python), I'm using Warnings Next Generation, but it does not seem to support shellcheck, yet. I'd like to have the violations visualized within my Jenkins Job dashboard. Does anyone have experience with that? Or perhaps a ready to use custom tool for Warnings NG?


Solution

  • I did find a feasible solution myself. Like suggested in the comments, spellcheck offers checkstyle format, which can be parsed and visualized with Warnings NG. The following Pipeline stage definition works fine.

    stage('Analyze') {
        steps {
            catchError(buildResult: 'SUCCESS') {
                sh """#!/bin/bash
                    # The null command `:` only returns exit code 0 to ensure following task executions.
                    shellcheck -f checkstyle *.sh > shellcheck.xml || :
                """
                recordIssues(tools: [checkStyle(pattern: 'shellcheck.xml')])
            }
        }
    }
    

    Running the build generates a nice trend diagram like follows.

    enter image description here