Reputation: 3608
I have a gitlab-runner image as follows:
Dockerfile
FROM alpine:3.6
RUN apk add --no-cache curl bash
COPY trigger-jenkins /usr/local/bin/trigger-jenkins
ENTRYPOINT ["/bin/bash"]
Its purpose is to trigger a Jenkins job. Running this with:
docker run -ti jenkins-runner:latest trigger-jenkins job_name
works perfectly fine. But when I tried to do the same by:
.gitlab-ci.yml
Jenkins Trigger:
script:
- trigger-jenkins job_name
tags:
- Jenkins
The pipeline fails like this:
Running with gitlab-ci-multi-runner 9.3.0 (3df822b)
on Jenkins Trigger (12475d61)
Using Docker executor with image jenkins-runner:latest ...
Using docker image sha256:44dedf0b3485e0e57107e2745739e1a252fb64c4161465e1b5ccc1119a1183bf for predefined container...
Using docker image jenkins-runner:latest ID=sha256:4760a8ef9139ee9c9a56c686de780fc49e176fe4294e1f0db4f431e117b6811c for build container...
Running on runner-12475d61-project-6-concurrent-0 via cc960a3794a0...
Cloning repository...
Cloning into '/builds/dev/Project'...
Checking out 874b2eac as test/jenkins...
Skipping Git submodules setup
/bin/sh: /bin/sh: cannot execute binary file
/bin/sh: /bin/sh: cannot execute binary file
ERROR: Job failed: exit code 126
I searched for the error code, but was not able to find an explanation.
What am I missing?
Upvotes: 5
Views: 9461
Reputation: 146630
The issue was not because of exec. The issue was probably this, your entrypoint was /bin/bash
and Gitlab CI was trying to execute /bin/sh
which is an executable. Leads to something like below
/bin/bash /bin/sh command args
Which is what the complaint we see as. Cannot execute binary file. What your entrypoint
should have been is below
ENTRYPOINT ["/bin/bash", "-c"]
Which would have made sure a command gets execute by bash and whether it is another shell or bash it would have worked. No need to modify and created entrypoint.sh
Upvotes: 11
Reputation: 3608
I continued my research and found the repository of the official maven docker images.
They solved a similar problem by creating a mvn-entrypoint.sh
. So I tried the same:
entrypoint.sh
#!/bin/sh
export PATH=$PATH:/usr/local/bin/
exec "$@"
This did the trick.
Upvotes: 1