通过GitLab CI扩展,为其他人的发布分支和手册自动部署DEPLOY作业

问题描述 投票:0回答:2

下一个解决方案应该有效。

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次。

I think it would be a good idea to write something like:

.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中做类似的事情?


另一个直截了当的想法是

move script: to separate file deploy_script.sh

并在萌芽状态完成问题。

deployment yaml gitlab-ci
2个回答
3
投票

这是https://docs.gitlab.com/ce/ci/yaml/README.html#extends

extends

在GitLab 11.3中引入

extends定义了一个条目名称,即使用extends的作业将继承。 extends可以替代使用YAML锚点,它更灵活,更易读。

.tests:
  only:
    refs:
      - branches

rspec:
  extends: .tests
  script: rake rspec
  stage: test
  only:
    variables:
      - $RSPEC

0
投票

感谢这个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

And even better:

inherit .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合并

© www.soinside.com 2019 - 2024. All rights reserved.