Docker build: returned a non-zero code: 1, when test is failed Docker build: returned a non-zero code: 1, when test is failed selenium selenium

Docker build: returned a non-zero code: 1, when test is failed


It may be that your tests are failing on an assertion and that failed assertion may be throwing the non 0 error code.

this link outlines the expected exit codes for each scenario

Exit code 0All tests were collected and passed successfullyExit code 1Tests were collected and run but some of the tests failedExit code 2Test execution was interrupted by the userExit code 3Internal error happened while executing testsExit code 4pytest command line usage errorExit code 5No tests were collected


Problem is when testcases are failing docker build is exiting with non-zero code.

One way around to generate report even when testcases are failed

echo "Build docker image and run container"docker build -t $IMAGE_NAME .echo "Copy allure-results into Jenkins container"rm -rf reportsdocker create -it --name $CONTAINER_NAME $IMAGE_NAME /bin/bashdocker cp $CONTAINER_NAME:my-project/reports/allure-results ./reportsdocker rm -f $CONTAINER_NAME

You can user report copy part in Jenkins pipeline in post stage under always block, so that whether build pass or fail you can always get reports.


I found a solution to this issue:added at the end of the RUN command - exit 0