我正在Jenkins上构建一条管道,以使用Docker容器测试和部署我的node.js应用程序。但是由于测试失败,我的管道被卡住了。我期望的行为是管道完成而不执行下一阶段,但不会卡住。
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"]
当我触发管道时:
Unit test
阶段,则一切正常,确定,并且应用程序开始运行。Unit test
阶段,则测试阶段开始,我得到14个测试通过和1个失败的结果,但是管道在此步骤中挂起,所以Run
步骤永不触发,并且管道保持在Running
状态。14个通过(2s)
1个失败
1 )正在检查用户的首次登录
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)
答案 0 :(得分:0)
需要退出较新版本的摩卡(mocha),否则服务器将继续运行,因此永远无法进入下一阶段。
mocha --exit