在GitLab的步骤脚本中,在加载Docker镜像后找不到或加载主类sh。

huangapple go评论76阅读模式
英文:

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

问题

Executing "step_script" 阶段的作业脚本 00:01 使用 Docker 镜像 sha256:75eb8c27787ee5c64311d798c9c0d2991a89024b516908 用于 gitlab-my_repo/maven3-jdk-8-git:V0.1,摘要为 gitlab-my_repo/maven3-jdk-8-git@sha256:febfe8e272bb8ccbb01116e7a177b979b53c080f11cafc ... 错误: 无法找到或加载主类 sh

当我使用 CI_DEBUG_TRACE=true 时,日志中没有其他内容...
对我来说,这是 Java 中的类路径问题,但为什么是 sh 而不是 src/java/class.main...
我们的 GitLab Runner 使用 Docker Dind,并且 maven3-jdk-8-git 的自定义镜像脚本如下:

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/* && \
    # 修正 Maven 以删除阻止的镜像
    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"]

我在 Dockerfile 中尝试了这行代码:RUN java -classpath /bin/sh sh,但在构建我的 Dockerfile 时出现了相同的错误(无法找到或加载主类 sh)。

英文:

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)

答案1

得分: 1

你的镜像包含 ENTRYPOINT ["/usr/bin/java"],这是导致问题的原因。GitLab CI 期望用于作业的镜像要么没有定义 ENTRYPOINT,要么具有 shell 入口点。

你可以从镜像中删除 entrypoint,或在你的 .gitlab-ci.yml 配置中覆盖它:

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

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"

huangapple
  • 本文由 发表于 2023年6月8日 22:55:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定