Search code examples
javadockerfilegitlab-cigitlab-ci-runner

During the step script of gitlab Could not find or load main class sh after load docker image


Executing "step_script" stage of the job script 00:01 Using docker image sha256:75eb8c27787ee5c64311d798c9c0d2991a89024b516908 for gitlab-my_repo/maven3-jdk-8-git:V0.1 with digest gitlab-my_repo/maven3-jdk-8-git@sha256:febfe8e272bb8ccbb01116e7a177b979b53c080f11cafc ... Error: Could not find or load main class sh

when i use CI_DEBUG_TRACE= true nothing else in the log.. For me it is a problem of classpath in java but why sh and not src/java/class.main... Our gitlab runner work with docker Dind and the script of the custom image of maven3-jdk-8-git is :

FROM maven:3.6.0-jdk-8 ENV TZ Europe/Paris ENV http_proxy XXXXXXXXXXXXXXXXXXX ENV https_proxy XXXXXXXXXXXXXXXXXXXX RUN sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list RUN sed -i 's|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list RUN sed -i '/stretch-updates/d' /etc/apt/sources.list RUN echo "Install Git" && \ apt-get update && apt-get install -y apt-transport-https ca-certificates apt-utils bzip2 git && \ rm -rf /var/lib/apt/lists/\* && \ \# Correction du maven pour supprimer le mirror bloquant line=$(grep -n maven-default-http-blocker /usr/share/maven/conf/settings.xml | awk -F: '{print $1}') && \ echo sed -i -e "$((line - 1)),$((line+5))d" /usr/share/maven/conf/settings.xml COPY ./settings.xml /tmp/settings.xml ENTRYPOINT \["/usr/bin/java"\]

I try this line in the dockerfile : RUN java -classpath /bin/sh sh and i have the same error in the build of my dockerfile lol (Could not find or load main class sh)


Solution

  • Your image includes ENTRYPOINT ["/usr/bin/java"], which is causing this problem. GitLab CI expects the images used for jobs to either have no ENTRYPOINT defined, or have a shell entrypoint.

    You can either remove the entrypoint from the image or override it in your .gitlab-ci.yml configuration:

    myjob:
      image: 
        name: my/custom/maven-image
        entrypoint: [""]
      script:
        - echo "hello gitlab"