在执行带有输入的步骤时出现“没有这样的文件或目录”

编程语言 2026-07-09

目前正在学习如何使用GitLab CI,受到文档的启发,可以在这里找到相关内容:herehere。在使用过程中我遇到了一个错误。

在一个 gitlab.com/namespace/zero-to-steps 仓库的 main 分支中,存在以下 steps/step.yml 文件:

spec:
  inputs:
    who:
      default: world
---
exec:
  command:
    - sh
    - -c
    - echo 'hello ${{inputs.who}}'

在一个测试仓库中,存在以下 .gitlab.ci 文件:

hello-world:
  run:
    - name: hello_world
      step: gitlab.com/namespace/zero-to-steps@main
      inputs:
        who: gitlab steps

hello-world-default:
  run:
    - name: hello_world
      step: gitlab.com/namespace/zero-to-steps@main

这是我得到的错误:

ERROR: Job failed: step "hello_world": failed to load: 
  fetching git func: loading function: 
    open /tmp/step-runner-cache/gitlab.com/namespace/zero-to-steps/.../steps/func.yml: 
      no such file or directory

我检查了以下几点:

  • step.yml 文件已正确放置在 steps 目录中
  • main 分支存在,且确实是正在使用的分支
  • URL没有拼写错误,且该URL之前就被使用过,未出现任何问题。

解决方案

这个错误具有误导性。

尽管在 CI/CD YAML语法参考 关于spec:inputs的描述,Step inputs看起来相似,但似乎差别很大。

可以在这里看到:

输入必须具有类型

为了解决这个问题,我们必须向输入规范中添加一个 type: string

spec:
  inputs:
    who:
      type: string
      default: world
---
exec:
  command:
    - bash
    - -c
    - echo 'hello ${{inputs.who}}'
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章