下一个解决方案应该起作用。
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
并解决问题。
答案 0 :(得分:3)
这是 https://docs.gitlab.com/ce/ci/yaml/README.html#extends
在GitLab 11.3中引入
extends
定义使用扩展名的作业将要继承的条目名称。
extends
可以替代使用YAML锚点,它更具灵活性和可读性。
.tests:
only:
refs:
- branches
rspec:
extends: .tests
script: rake rspec
stage: test
only:
variables:
- $RSPEC
答案 1 :(得分:0)
感谢此问答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: 'git@gitlab.com: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合并
的搜索答案 2 :(得分:0)
Gitlab现在通过rules
指令:https://docs.gitlab.com/ee/ci/yaml/#rules-clauses