I would like to run the npm command npm audit as part of the ci build and somehow display the output in a jenkins ci build.
If a critical vulnerability is found, I would like to fail the current build by returning a non zero exit code.
I would like to run the npm command npm audit as part of the ci build and somehow display the output in a jenkins ci build.
If a critical vulnerability is found, I would like to fail the current build by returning a non zero exit code.
I don't know of any plugins that would achive this but some manual parsing might work(if you are using a pipeline).
def output = sh script: "npm audit", returnStdout: true
def summary = output.split("\n")[-1] //get the summary from the last line
...
You then could use some regex or other string manipulation to find the number after critical. You also could use archiveArtifacts to save the entire output in the build history.
Inspired on this post, I've realized this by creating a custom 'Compiler Warnings parser';
[\w+-]+\s+([\w+-]+)\s+([\w\.-@]+)\s+(>=\s)*([\w\.-@]+)\s+(.+?(?=http))([\w\.-@]+)\s+(.*)
import hudson.plugins.warnings.parser.Warning
import hudson.plugins.analysis.util.model.Priority
priority = Priority.HIGH;
if ( "low" == matcher.group(2) ) {
priority = Priority.LOW;
}
else if ( "moderate" == matcher.group(2) ) {
priority = Priority.NORMAL;
}
String msg = "Vulnerability found in '" + matcher.group(1) + "' (" + matcher.group(6) + ") , prio: " + matcher.group(2) + " Fix: " + matcher.group(5) + " info: " + matcher.group(5);
return new Warning('package.json', 0, 'NSP Warning', matcher.group(1), msg, priority);
npm install
# parseable report for 'compile warning post build step'
npm audit --parseable >> npm_audit_report_parseable.txt || true # suppress npm audit error code
Optionally you can configure 'Health/Status thresholds'; this determines when a build fails, and when it is marked as unstable.
Another solutions: use the Dependency-Check Plugin
--scan /non/existing/dir
to avoid finding exploits in installed package related files like 'demo', 'docs', etc. because the 'dependency check plugin' performs a full recursive file scan which we do not need because the npm scanner finds the 'npm audit' findings already.