- 1 year ago
Calling npm install as a 'bat' command in Jenkins Pipeline: Error should make the build step fail
In a Jenkins Pipeline, you can use the bat
step to run a batch command (Windows) or shell script (Linux/Mac) as part of your build process. To ensure that the build step fails if the npm install
command encounters an error, you can add the returnStatus: true
parameter to the bat
step. This parameter will make the build step fail if the exit code of the npm install
command indicates an error.
Here's an example of how to use the bat
step in a Jenkins Pipeline to run npm install
and fail the build if it encounters an error:
groovypipeline {
agent any
stages {
stage('Build') {
steps {
// Run npm install and fail the build if it encounters an error
bat 'npm install'
}
}
}
}
With the returnStatus: true
parameter, Jenkins will consider the build step a failure if the npm install
command exits with a non-zero exit code, indicating an error.
If you have additional build steps in your pipeline, you can continue with the next stages as needed. If npm install
fails, the pipeline will stop executing the subsequent stages, and the build will be marked as failed.
Note: The returnStatus
parameter was introduced in Jenkins version 2.176.1. If you are using an older version of Jenkins, you may need to upgrade to use this parameter.