Jenkins Pipeline builds Dockerfile but can’t run steps inside container

I’m building a FreePascal web application and I’m using Jenkins pipeline for CI/CD.

I have the following Dockerfile (not the most efficient thing in the world, but its okay for now):

FROM ubuntu as builder

RUN apt-get update -y
RUN apt-get install -y libcurl4-openssl-dev
RUN apt-get install -y fpc

ARG BUILD_TYPE=prod
ENV BUILD_TYPE=${BUILD_TYPE}

COPY . /var/www/app
WORKDIR /var/www/app

RUN make build
RUN make build-tests

FROM actilis/httpd-cgi

RUN yum -y install postgresql

ENV HTTPD_ENABLE_CGI=true

COPY ./httpd.conf  /etc/httpd/conf.d/000-default.conf

COPY --from=builder /var/www/app/public/app.cgi /var/www/app/
COPY --from=builder /var/www/app/bin/unit/TestRunner /var/www/app/

When I sh into this container and cd into /var/www/app, I see ./TestRunner and app.cgi; these are my unit-tests and my cgi application executables respectively. I can run:

./TestRunner --format=xml --all

and all the tests will run. So far so good.

The problem is when I try to recreate the same setup on Jenkins.
I’m using the following Jenkinsfile:

pipeline {
    agent none
    stages {
        stage('Back-end') {
            agent {
                dockerfile {
                    filename 'Dockerfile'
                    dir 'backend'
                }
            }
            steps {
                sh './TestRunner --format=xml --all'
            }
        }
        stage('Front-end') {
            agent {
                docker { image 'node:7-alpine' }
            }
            steps {
                sh 'node --version'
            }
        }
    }
}

On Jenkins, it is unable to find the ./TestRunner file. The output is:

+ docker build -t 181ef0bcb3bf204f1879365a51eb4f056599fcbc -f backend/Dockerfile backend
Sending build context to Docker daemon  1.405MB

Step 1/16 : FROM ubuntu as builder
 ---> 4c108a37151f
Step 2/16 : RUN apt-get update -y
 ---> Using cache
 ---> 23006844dbe3
Step 3/16 : RUN apt-get install -y libcurl4-openssl-dev
 ---> Using cache
 ---> 85f33caeb6fa
Step 4/16 : RUN apt-get install -y fpc
 ---> Using cache
 ---> 4179833a6dc6
Step 5/16 : ARG BUILD_TYPE=prod
 ---> Using cache
 ---> 175016eb89cd
Step 6/16 : ENV BUILD_TYPE=${BUILD_TYPE}
 ---> Using cache
 ---> 93f40d4821b4
Step 7/16 : COPY . /var/www/app
 ---> Using cache
 ---> ba927c86c8f0
Step 8/16 : WORKDIR /var/www/app
 ---> Using cache
 ---> ad053831767b
Step 9/16 : RUN make build
 ---> Using cache
 ---> 7cee4fa21f10
Step 10/16 : RUN make build-tests
 ---> Using cache
 ---> 1d7db41bc613
Step 11/16 : FROM actilis/httpd-cgi
 ---> 98b08d011dc9
Step 12/16 : RUN yum -y install postgresql
 ---> Using cache
 ---> 2dd8ccfec261
Step 13/16 : ENV HTTPD_ENABLE_CGI=true
 ---> Using cache
 ---> 1a78db6d4788
Step 14/16 : COPY ./httpd.conf  /etc/httpd/conf.d/000-default.conf
 ---> Using cache
 ---> 4147b79edb69
Step 15/16 : COPY --from=builder /var/www/app/public/app.cgi /var/www/app/
 ---> Using cache
 ---> 41f28ebd3602
Step 16/16 : COPY --from=builder /var/www/app/bin/unit/TestRunner /var/www/app/
 ---> Using cache
 ---> f897e3055e8b
Successfully built f897e3055e8b
Successfully tagged 181ef0bcb3bf204f1879365a51eb4f056599fcbc:latest
[Pipeline] dockerFingerprintFrom
[Pipeline] sh
+ docker inspect -f . 181ef0bcb3bf204f1879365a51eb4f056599fcbc
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 111:115 -w /home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline -v /home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline:/home/jenkins/workspace/ipeline-2_chore_jenkins-pipeline:rw,z -v /home/jenkins/workspace/[email protected]:/home/jenkins/workspace/[email protected]:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 181ef0bcb3bf204f1879365a51eb4f056599fcbc cat
$ docker top c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4 -eo pid,comm
[Pipeline] {
[Pipeline] sh
+ find . -name '*TestRunner*'
./backend/tests/TestRunner.pas
[Pipeline] sh
+ ./TestRunner --format=xml --all
/home/jenkins/workspace/[email protected]/durable-43156271/script.sh: line 1: ./TestRunner: No such file or directory
[Pipeline] }
$ docker stop --time=1 c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4
$ docker rm -f c669acb2b4a88c4ea0cfc1f5682f2cfd2a41052235767ac330800f7bcd6b35b4
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Front-end)
Stage "Front-end" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline

I investigated what’s inside the container and all I found are the original source files from Github. Even though the log output shows that Docker ran successfully, the executables aren’t there.

Could someone please explain what’s going on and how to fix this?
I’m new to Jenkins so I might be making an elementary mistake.

Source: StackOverflow