如何向从模板继承的before_script添加命令

jea*_*pic 2 continuous-integration yaml gitlab-ci

假设我有一个模板,其中包含以下内容:

.some-scripts: &some-scripts |
    set -e

    function somefunction() {
       
    }

.template-job:
  before_script:
    - *some-scripts
    - echo "Example command"
    - somefunction

build-job:
  extends: .template-job
  stage: build
  script: 
    - mvn build
Run Code Online (Sandbox Code Playgroud)

该模板包含在另一个 gitlab-ci.yml 中,我希望向构建作业的 before_script 添加一些特定命令,而不覆盖模板作业的 before_script。这可能吗?如何实现?

jea*_*pic 5

我找到了我要找的东西,我需要使用参考标签

这是我想出的:

build-job:
  stage: build
  before_script: 
    - !reference [.template-job, before_script]
    - mycommand
    - mysecondcommand
  script: 
    - mvn build
Run Code Online (Sandbox Code Playgroud)