FROM python:3.7-alpine
ARG TEST_COMMAND=false
ARG TEST_ENABLED=true
# This will eval test command and fail but not stop build process because exit
# status of echo command issued after is 0 (shell scripts are weird)
RUN $TEST_ENABLED && eval "$TEST_COMMAND" || echo "skipping test"
RUN echo "This line should not be reached but shell scripts are weird"
ARG TEST_COMMAND=true
ARG TEST_ENABLED=true
# This will eval test command and continue
RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
ARG TEST_COMMAND=true
ARG TEST_ENABLED=false
# This will echo skipping test and continue
RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
ARG TEST_COMMAND=false
ARG TEST_ENABLED=true
# This will eval test command and exit build due to failure on the last command issued
RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
RUN echo "This line will not be reached"
Sending build context to Docker daemon 7.168kB
Step 1/15 : FROM python:3.7-alpine
---> 56dc68fee36a
Step 2/15 : ARG TEST_COMMAND=false
---> Running in de211fa1c2d6
Removing intermediate container de211fa1c2d6
---> ed5bac9854bd
Step 3/15 : ARG TEST_ENABLED=true
---> Running in c999a4888e87
Removing intermediate container c999a4888e87
---> a0c362210387
Step 4/15 : RUN $TEST_ENABLED && eval "$TEST_COMMAND" || echo "skipping test"
---> Running in 27f98332f464
skipping test
Removing intermediate container 27f98332f464
---> 5e4a650ff9e1
Step 5/15 : RUN echo "This line should not be reached but shell scripts are weird"
---> Running in 326d2348ee11
This line should not be reached but shell scripts are weird
Removing intermediate container 326d2348ee11
---> 53a151b471cf
Step 6/15 : ARG TEST_COMMAND=true
---> Running in c82366620ca6
Removing intermediate container c82366620ca6
---> e7ae1ecc6ec3
Step 7/15 : ARG TEST_ENABLED=true
---> Running in 79eda4689ae1
Removing intermediate container 79eda4689ae1
---> fa44fc900b13
Step 8/15 : RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
---> Running in bb1e8a9b753f
Removing intermediate container bb1e8a9b753f
---> d6356b498eb7
Step 9/15 : ARG TEST_COMMAND=true
---> Running in 34bab57abdd2
Removing intermediate container 34bab57abdd2
---> 5aac21c7027e
Step 10/15 : ARG TEST_ENABLED=false
---> Running in 18ff5a03cdb0
Removing intermediate container 18ff5a03cdb0
---> c8f1121a41b3
Step 11/15 : RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
---> Running in 7a8e26b5380a
skipping test
Removing intermediate container 7a8e26b5380a
---> 5e43c9bc5054
Step 12/15 : ARG TEST_COMMAND=false
---> Running in 9d731ff4ed53
Removing intermediate container 9d731ff4ed53
---> 5b73c364c92f
Step 13/15 : ARG TEST_ENABLED=true
---> Running in 42640257adfa
Removing intermediate container 42640257adfa
---> 8b285904be7d
Step 14/15 : RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"
---> Running in 3821450840a9
The command '/bin/sh -c [ "$TEST_ENABLED" = "false" ] && echo "skipping test" || eval "$TEST_COMMAND"' returned a non-zero code: 1