假设我有一个模板,它包含如下内容:
.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
此模板包含在另一个gitlab-ci中。yml和我正在寻找添加一些特定的命令到我的构建作业的before_script而不覆盖模板作业的before_script。这可能吗?如何实现?
我找到了我要找的东西,我需要使用一个参考标签。
这是我想到的:
build-job:
stage: build
before_script:
- !reference [.template-job, before_script]
- mycommand
- mysecondcommand
script:
- mvn build
目前不能扩展before_script
,只能覆盖它。但是有一个关于扩展行为的开放问题。
作为一种解决方案,您可以将额外的命令添加到script
部分,因为before_script
,script
和after_script
最终在执行时合并在一起。
.template-job:
before_script:
- echo "Example command"
- echo "Second command"
build-job:
extends: .template-job
stage: build
script:
- echo "third command"
- echo "fourth command"
- mvn build