1

Jenkins pipeline passes the npm run test stage even if no mongo connection is found and no test run.
This is the simple Jenkinsfile test section:

code{ 
  stage('Checkout')
  {
    echo 'Getting source code...'
    checkout scm
  }
  stage('Build Test Environment') 
  {
    echo 'Building dependencies...'
    sh 'npm i'
  }
  stage('Runnin Test') 
  {
    echo 'Testing...'
    sh 'npm run test'
  }

I am running mongo locally on the build server as docker image.
And I get this error:

MongoError: failed to connect to server mongo

But I want my build to fail if no mongo connection is found or the test cases fail.

zx485
  • 28,498
  • 28
  • 50
  • 59
Siffy
  • 11
  • 1
  • Possible duplicate of [mongodb Failed: error connecting to db server: no reachable servers](https://stackoverflow.com/questions/32195997/mongodb-failed-error-connecting-to-db-server-no-reachable-servers) – Amjad Khan Mar 24 '18 at 10:25
  • I want my build process to be failed if db connection not found. – Siffy Mar 24 '18 at 18:38
  • Check the exit code of the shell command. It must be coming back as 0 if Jenkins is not failing it, suggesting the problem is inside the test. – metalisticpain Mar 26 '18 at 12:08

0 Answers0