I'm trying to run a shell script file inside a docker container. It's working as expected when testing it with the command line but not when running it inside Jenkins.
This is my Dockerfile:
FROM ubuntu:latest
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y \
build-essential libgtest-dev \
&& apt-get clean
WORKDIR /src
COPY . .
#working when using CLI and Jenkinsfile
RUN echo "test"
#working when using CLI and Jenkinsfile
RUN ls
#working when using CLI but NOT with Jenkinsfile
RUN ./build.sh
CMD ["./run_tests.sh"]
And this is how I run the dockerfile:
docker-build.sh
#!/bin/sh
set -x
#stop and rm old container if any
docker container stop build-fw
docker container rm build-fw
docker build -t build-fw .
docker run --name build-fw -d -it build-fw
docker logs build-fw
docker container stop build-fw
docker container rm build-fw
In Jenkins, I simply created a Freestyle project with the "Execute Shell" build step, where I simply ran the "docker-build.sh" script:
Execute Shell
./docker-build.sh
I got the following error output:
#12 0.586 /bin/sh: 1: ./build.sh: not found
#12 ERROR: executor failed running [/bin/sh -c ./build.sh]: exit code: 127
------
> [8/8] RUN build.sh:
------
executor failed running [/bin/sh -c ./build.sh]: exit code: 127
The error states, that ./build.sh was not found, although RUN ls shows that build.sh exists.
Why is it the case?