gpt4 book ai didi

gitlab - 非常简单的gitlab-ci.yml报告语法错误

转载 作者:行者123 更新时间:2023-12-02 02:41:57 28 4
gpt4 key购买 nike

我写了一个非常简单的.gitlab-ci.yml,如下所示:

image: horchen/vscode-ext-dev

job1:
script:
- echo "Hello World"

只要回显Hello World,我想它应该可以在任何平台上运行。但gitlab-ci总是告诉我其中有语法错误。

Running with gitlab-runner 13.2.2 (a998cacd)
on nodejs-ci aPuhC2uZ
Preparing the "docker" executor
Using Docker executor with image horchen/vscode-ext-dev ...
Using locally found image version due to if-not-present pull policy
Using docker image sha256:17af24ad877daa656e102508585c7262585be04b05a75cc89833afcfe7403ebb for horchen/vscode-ext-dev ...
Preparing environment
Running on runner-apuhc2uz-project-1-concurrent-0 via cf9f41a14878...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/horchen/vscode-rlcv/.git/
Checking out 93d3b0e1 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
[: line 1: syntax error: unexpected end of file (expecting "then")
ERROR: Job failed: exit code 2

有人知道为什么会报这样的错误吗?

---------------- 追加数据 -------------------

其实我确实是在windows上开发的,但是我检查了CR/LF风格,也检查了hexdump。并尝试在webIDE和linux VIM上编辑它,都没有找到^M。

  Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   
00000000: 69 6D 61 67 65 3A 20 68 6F 72 63 68 65 6E 2F 76 image:.horchen/v
00000010: 73 63 6F 64 65 2D 65 78 74 2D 64 65 76 0A 0A 61 scode-ext-dev..a
00000020: 66 74 65 72 5F 73 63 72 69 70 74 3A 0A 20 20 2D fter_script:...-
00000030: 20 22 72 6D 20 2A 2E 76 73 69 78 22 0A 0A 6A 6F ."rm.*.vsix"..jo
00000040: 62 31 3A 0A 20 20 73 63 72 69 70 74 3A 0A 20 20 b1:...script:...
00000050: 20 20 2D 20 65 63 68 6F 20 22 48 65 6C 6C 6F 20 ..-.echo."Hello.
00000060: 57 6F 72 6C 64 22 0A World".

最佳答案

作业的 step_script 阶段包括 before_scriptscript 部分。您的执行程序正在尝试执行您的 script 部分,这导致了错误。

行尾错误

意外的文件结束(预期“then”) 错误在 Windows 与 Linux 文件格式中经常出现。请参阅Syntax error: end of file unexpected (expecting "then") 。尝试将您的 gitlab-ci.yml 文件转换为具有 Linux 行结尾,看看是否可以解决问题。有许多工具可以执行此操作(请参阅上面的链接),包括 Notepad++

如果这是您的问题,那么您可能会遇到更大的问题:您是在 Windows 中进行开发并在 Linux 中运行代码吗?如果是这样,您可能需要设置 .gitattirbutes 文件以自动将 Windows EOL 字符转换为 Linux,反之亦然。请参阅How to change line-ending settings .

添加第二个作业,不带回显

如果这不起作用,请尝试向管道中添加另一个不打印任何内容的作业。只需将诸如 x=2 之类的内容添加到 script 部分即可。这可能会消除脚本中作为错误来源的echo

将作业分配给阶段

为了安全起见,创建一个 stages 部分并将两个作业分配到同一阶段,如下所示:

stages:
- test

job2:
stage: test
script:
- x = 2

Dockerfile 故障排除

如果仍然没有帮助,那么我会开始怀疑您的 Docker 镜像:horchen/vscode-ext-dev。 GitLab 可能正在尝试从容器中的作业执行脚本,这可能会先执行一些代码。您可能需要发布您的 Dockerfile 来解决该问题。

我还会怀疑 Dockerfile 调用的任何脚本的 EOL CRLF/LF 字符。

关于gitlab - 非常简单的gitlab-ci.yml报告语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63450458/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com