下一个解决方案应该有效。
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:
to separate file deploy_script.sh
并在萌芽状态完成问题。
这是https://docs.gitlab.com/ce/ci/yaml/README.html#extends
在GitLab 11.3中引入
extends
定义了一个条目名称,即使用extends的作业将继承。
extends
可以替代使用YAML锚点,它更灵活,更易读。
.tests:
only:
refs:
- branches
rspec:
extends: .tests
script: rake rspec
stage: test
only:
variables:
- $RSPEC
感谢这个Q&A yaml repeated node that is a key
.deploy_base: &deploy_base
stage: deploy
tags:
- linux
retry: 2
script: &deploy_script
- do_action 1
- do_action 2
- git push artifacts
deploy_release:
only: &deploy_release_only
- master
- stable
script: *deploy_script
deploy_manual:
except: *deploy_release_only
when: manual
script: *deploy_script
.deploy_base
:.deploy_base: &deploy_base
stage: deploy
tags:
- DlpcsCore
- linux
retry: 2
variables:
URL: '[email protected]:Yahoo/HeavenShine-bin.git'
script: &deploy_script
- do_act_1
- do_action_2
deploy_release:
<< : *deploy_base
only: &deploy_release_only
- master
- stable
- CI
#- /^master[-_].+$/
#- /^(.+)[+]bin$/
deploy_manual:
<< : *deploy_base
except: *deploy_release_only
when: manual
要了解更多搜索YAML合并