现在我正在尝试在 GitLab 上学习 CI/CD。不幸的是,我无法在我的项目上运行简单的管道。跑步者似乎无法以某种方式工作。 这是该项目的图片:
我在我的 .gitlab-ci.yml 文件中写了这个:
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
这只是 GitLab 教程中用于创建简单管道的原始代码。
不幸的是我之后收到此错误:
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
我正在使用 GitLab 的共享运行器作为管道。 任何帮助将不胜感激!
该作业正在尝试使用图像
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
配置中没有任何内容会导致使用此图像,这可能是由您正在使用的运行程序的配置引起的,该配置在没有 image:
键时将其指定为默认图像。
您可以指定不同的图像来解决此问题:
image: alpine # as a global key default
build-job:
stage: build
image: alpine # or on a per-job basis
如果你真的想使用这个特定的图像(你几乎肯定不会),你需要覆盖入口点:
build-job:
stage: build
image:
name: gcr.io/kaniko-project/executor
entrypoint: [""]
如果您管理 GitLab 运行程序配置,则应将默认的
image
配置更改为可用的图像。
尝试
gcr.io/kaniko-project/executor:debug
它对我来说效果很好: https://gitlab.freedesktop.org/joel.winarske/docker-containers/-/blob/main/.gitlab-ci.yml#L2