简体   繁体   中英

Failed test is hanging Jenkins pipeline

I am making a pipeline on Jenkins to test and deploy my node.js application using Docker containers. But I am getting my pipeline stuck because a test is failing. The behaviour I would expect is pipeline finishes without executing next stages but it will not get stuck.

Jenkinsfile :

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh '''docker build --tag my-web:$BUILD_NUMBER .
docker stop my-web&& docker rm my-web
echo "Build step finished"'''
      }
    }
    stage('Unit test') {
      steps {
        sh '''docker build -t my-web-test -f Dockerfile.test .
docker run --rm my-web-test
'''
      }
    }
    stage('Run') {
      steps {
        sh '''docker run --name my-web -p 3000:3000 my-web:$BUILD_NUMBER node /var/www/index.js &
'''
        echo 'RUNNING'
      }
    }
    stage('End') {
      steps {
        echo 'End of pipeline'
      }
    }
  }
}

Dockerfile.test :

FROM node:alpine

RUN mkdir /var/test
WORKDIR /var/test
COPY package.json /var/test/
RUN npm install && npm install -g mocha
COPY src/ /var/test/
CMD ["mocha", "tests/", "--recursive"]

When I trigger the pipeline:

  • If I remove Unit test stage from pipeline everything works OK and application begins running.
  • If I do not remove Unit test stage, testing stage begins and I get a result of 14 test passed and 1 failed but the pipeline hangs in this step so Run step never triggers and the pipeline keeps in Running status.

14 passing (2s)

1 failing

1 ) Checking user first-time-login

  Should redirect to change-password page: Error: expected "Location" of "/dashboard/change-password", got "/dashboard" at Test._assertHeader (node_modules/supertest/lib/test.js:249:12) at Test._assertFunction (node_modules/supertest/lib/test.js:283:11) at Test.assert (node_modules/supertest/lib/test.js:173:18) at localAssert (node_modules/supertest/lib/test.js:131:12) at /var/test/node_modules/supertest/lib/test.js:128:5 at Test.Request.callback (node_modules/superagent/lib/node/index.js:728:3) at IncomingMessage.<anonymous> (node_modules/superagent/lib/node/index.js:916:18) at endReadableNT (_stream_readable.js:1154:12) at processTicksAndRejections (internal/process/task_queues.js:77:11) 

需要退出较新版本的Mocha,否则服务器将继续运行,因此永远不会到达下一阶段。

mocha --exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM