下一个解决方案应该有效。
deploy_release:
stage: deploy
tags:
- linux
only:
- master
- stable
retry: 2
script:
- do_action 1
- do_action 2
- git push artifacts
deploy_manual:
stage: deploy
tags:
- linux
except:
- master
- stable
when: manual
retry: 2
script:
- do_action 1
- do_action 2
- git push artifacts
但它有一个☝️重大缺陷 - script:
重复了 2 次。
我认为编写如下内容是个好主意:
.deploy_base:
stage: deploy
tags:
- linux
retry: 2
script:
- do_action 1
- do_action 2
- git push artifacts
deploy_release:
include: .deploy_base
only:
- master
- stable
deploy_manual:
include: .deploy_base
except:
- master
- stable
when: manual
但我怀疑这是否可行。 是否可以在 YAML 中执行类似的操作?
另一个简单的想法是
将 script:
移动到单独的文件 deploy_script.sh
把问题解决在萌芽状态。
请您参考如下方法:
这里是 https://docs.gitlab.com/ce/ci/yaml/README.html#extends
extends
Introduced in GitLab 11.3
extends
定义使用扩展的作业将继承的条目名称。
扩展
作为使用 YAML anchor 的替代方案,它更加灵活和可读。
.tests:
only:
refs:
- branches
rspec:
extends: .tests
script: rake rspec
stage: test
only:
variables:
- $RSPEC