Docker Community Forums

Share and learn in the Docker community.

Continue on Docker Exit (1) / Suppress and Continue next NPM command (noob question)


Sorry for the very noob questions. I have built an automation suite that runs on a docker container. If there is a failure in the suite, then an exit code of 1 is returned. This in turn ends the process. What this means is my chained npm command is not run. This command generates a html report.

FROM ubuntu:20.04
WORKDIR /testing

ARG portal
ENV cypress_portal=$portal
ARG protection
ENV cypress_protection=$protection
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
    libgtk2.0-0 \
    libgtk-3-0 \
    libgbm-dev \
    libnotify-dev \
    libgconf-2-4 \
    libnss3 \
    libxss1 \
    libasound2 \
    libxtst6 \
    xauth \
    xvfb \
    curl \

RUN curl -sL  | bash -
RUN apt-get -y install nodejs
RUN curl -LO
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb 
COPY . .
RUN npm install
CMD npm run cypress:run && npm run report:generate

npm run cypress:run. → Runs and 1/100 test fail.
Throws exit code (1)

is there any way on an exit code 1, that i can get the npm report:generate to run?

Any help is really appreciated.


Not sure if it will work, but you can try:

CMD npm run cypress:run; exit 0 && npm run report:generate

That would exit before running the last command. Using semicolon instead of && is enough

npm run cypress:run; npm run report:generate

When bash is configured to stop whenever an error occures (set -eu -o pipefail) then you can use the command true like this:

npm run cypress:run || true; npm run report:generate

but this is not necessary in this case.

Ta all, resolved in the end by doing:

CMD npm run cypress:run ; stored_exit_code=$? ; npm run report:generate ; exit $stored_exit_code

1 Like

So you still return the original exit code from the container. That is a good idea!