Any pipeline resolves in Error: unknown command “sh” for “executor” Run ‘executor –help’ for usage.

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

Any pipeline resolves in Error: unknown command "sh" for "executor" Run 'executor --help' for usage

问题

Right now I am trying to learn CI/CD on GitLab. Unfortunately, I cant make a simple pipeline run on my project. The runner doesn't seem to work somehow.

Here is an image of the project:
Any pipeline resolves in Error: unknown command “sh” for “executor” Run ‘executor –help’ for usage.

I wrote this in my .gitlab-ci.yml file:

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"

test-job1:
  stage: test
  script:
    - echo "This job tests something"

test-job2:
  stage: test
  script:
    - echo "This job tests something, but takes more time than test-job1."
    - echo "After the echo commands complete, it runs the sleep command for 20 seconds"
    - echo "which simulates a test that runs 20 seconds longer than test-job1"
    - sleep 20

deploy-prod:
  stage: deploy
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
  environment: production

which is just the original code from the GitLab Tutorial for creating a simple pipeline.

Unfortunately, I get this error afterwards:

Using docker image sha256:7053f62a27a84985c6ac886fcb5f9fa74090edb46536486f69364e3360f7c9ad for gcr.io/kaniko-project/executor:debug with digest gcr.io/kaniko-project/executor@sha256:fcccd2ab9f3892e33fc7f2e950c8e4fc665e7a4c66f6a9d70b300d7a2103592f ...
Error: unknown command "sh" for "executor"
Run 'executor --help' for usage

I'm using the shared runners of GitLab for the pipelines.
Any help would be very appreciated!

英文:

Right now I am trying to learn CI/CD on GitLab. Unfortunately, I cant make a simple pipeline run on my project. The runner doesn't seem to work somehow.
Here is an image of the project:
Any pipeline resolves in Error: unknown command “sh” for “executor” Run ‘executor –help’ for usage.

I wrote this in my .gitlab-ci.yml file:

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"

test-job1:
  stage: test
  script:
    - echo "This job tests something"

test-job2:
  stage: test
  script:
    - echo "This job tests something, but takes more time than test-job1."
    - echo "After the echo commands complete, it runs the sleep command for 20 seconds"
    - echo "which simulates a test that runs 20 seconds longer than test-job1"
    - sleep 20

deploy-prod:
  stage: deploy
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
  environment: production

which is just the original code from the GitLab Tutorial for creating a simple pipeline.

Unfortunately i get this error afterwards:

Using docker image sha256:7053f62a27a84985c6ac886fcb5f9fa74090edb46536486f69364e3360f7c9ad for gcr.io/kaniko-project/executor:debug with digest gcr.io/kaniko-project/executor@sha256:fcccd2ab9f3892e33fc7f2e950c8e4fc665e7a4c66f6a9d70b300d7a2103592f ...
Error: unknown command "sh" for "executor"
Run 'executor --help' for usage

I'm using the shared runners of GitLab for the pipelines.
Any help would be very appreciated!

答案1

得分: 2

The job is trying to use the image gcr.io/kaniko-project/executor, 但这个镜像定义了一个 ENTRYPOINT,指向 /kaniko/executor 二进制文件,因此不适用于作为 GitLab CI 中的作业镜像。详细解释请查看 此答案。基本上,GitLab 试图发送命令到作业容器,但意外地调用了 executor 二进制文件,导致错误消息来自 /kaniko/executor

Error: unknown command "sh" for "executor"
Run 'executor --help' for usage

由于你的 .gitlab-ci.yml 配置中没有导致使用此镜像的原因,这可能是由你正在使用的 runner 配置引起的,默认情况下没有 image: 键时会指定此镜像。

你可以指定不同的镜像来解决这个问题:

image: alpine  # 作为全局键默认值

build-job:
  stage: build
  image: alpine # 或在每个作业的基础上

如果你确实想使用此特定镜像(几乎肯定不需要),你需要覆盖 entrypoint:

build-job:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor
    entrypoint: [""]

如果你管理 GitLab runner 配置,应该更改默认的 image 配置为可用的镜像。

英文:

The job is trying to use the image gcr.io/kaniko-project/executor -- but this image defines an ENTRYPOINT that points to the /kaniko/executor binary and is therefore not compatible to be used as a job image in GitLab CI. See this answer for a full explanation of why this is problematic. Basically gitlab is trying to send commands to the job container, but is unexpectedly calling the executor binary, which results in the error message which comes from /kaniko/executor

Error: unknown command "sh" for "executor"
Run 'executor --help' for usage

Because there's nothing in your .gitlab-ci.yml configuration that would cause this image to be used, this is likely caused by the configuration of the runner you are using which specifies this as the default image when no image: key is present.

You can specify a different image to get around this problem:

image: alpine  # as a global key default

build-job:
  stage: build
  image: alpine # or on a per-job basis

If you really want to use this particular image (you almost certainly do not), you'll need to override the entrypoint:

build-job:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor
    entrypoint: [""]

If you manage the GitLab runner configuration, you should change the default image configuration to be a usable image.

huangapple
  • 本文由 发表于 2023年5月25日 22:56:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333658.html
匿名

发表评论

匿名网友

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

确定