I have a jenkins pipeline with docker for node/npm builds. If they fail, Jenkins still shows the build as succeeding. How do I make it detect the failure?
My jenkins file looks like this:
stage('Deploy Staging') {
when {
branch 'staging'
}
steps {
sh 'ssh [email protected] "cd project; git checkout staging; git fetch origin staging; git reset --hard origin/staging; COMPOSE_FILE=build/staging/docker-compose.yml make build-all; COMPOSE_FILE=build/staging/docker-compose.yml make up;"'
discordSend description: "Staging pipeline build status: ${currentBuild.currentResult}", link: env.BUILD_URL, result: currentBuild.currentResult, title: JOB_NAME, webhookURL: 'url'
}
}
2
Answers
I ended up having to make sure the
make build-all
had an explicit|| exit 1
at the end for this to exit correctly.This is a solution that is not specific to npm build failures, but you could consider using the Log Parser plugin. This plugin allows you to set console parsing rules which takes the console output of the log and scans it for parsing rules that you specify. You can then make the build fail/pass/warn when text that matches these rules are encountered.
So in your case you could make a rule that matches to your npm build failure message and force the build to fail when the build failure occurs.