在对步骤引用进行插值时找不到属性

编程语言 2026-07-09

目前正在学习如何使用GitLab CI,受到文档的启发,我们可以在这里这里 找到相关资料,结果遇到了一个错误。

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

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

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

spec:
  inputs:
    ref:
      description: Reference to include.
      default: main
---
hello-world:
  run:
    - name: hello_world
      step: gitlab.com/namespace/zero-to-steps@${{inputs.ref}}
      inputs:
        who: gitlab steps

我遇到了以下错误:

ERROR: Job failed: step "hello_world": failed to load: fetching func: 
    interpolating reference: [48:52] evaluating expression failed at 
    ".ref": attribute not found

使用诸如 main 这样的硬编码引用时可以工作,但进行插值时就不行。

解决方案

表达式 与模板插值不同,后者使用双重方括号 ($[[ ]] ),并在作业生成期间进行求值。

所谓的“经典”字符串插值使用以下语法: $[[ inputs.stuff ]],如这里所示:

在头部区域之外使用 $[[ inputs.input-id ]] 插插值格式来声明输入应使用的位置。

但在steps中,插值格式使用成对的大括号而不是成对的方括号,因为它是在不同的时机进行插值。

如果只看步骤文档而错过这段关于不同插值类型的专门说明,就会非常困惑,因为文档中没有关于方括号输入插值的其他实例。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章