Skip to content

Instantly share code, notes, and snippets.

@benhodgson87
Last active July 3, 2020 09:27
Show Gist options
  • Save benhodgson87/3a081873dbb33911130cf2e745835724 to your computer and use it in GitHub Desktop.
Save benhodgson87/3a081873dbb33911130cf2e745835724 to your computer and use it in GitHub Desktop.
Jenkins step to run Yarn Audit exiting only on critical level vulnerabilities
// Run yarn audit and only exit 0 on critical vulnerabilities (greater than 8)
// https://github.com/yarnpkg/yarn/blob/298e0ea6cea3ab8a610cabf28de3fdf8e7fa8d1f/src/cli/commands/audit.js#L158-L162
//
// Credit: https://github.com/yarnpkg/yarn/issues/7260#issuecomment-506556626
stage('Node dependencies') {
steps {
sh script: '/bin/bash -c "yarn audit; [[ $? -ge 8 ]] && exit 1 || exit 0"', label: "Vulnerability audit"
sh script: 'yarn', label: 'Install dependencies'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment