CI Config: Allow Manual Script Definitions for `when` Option

Description

Using Manual Actions with specific selections are helpful, but being able to run arbitrary scripts with echo'd status codes could open up extreme flexibility.

Example: I would like a mixture of Continuous Deployment and Continuous Delivery. For example:

Use Cases

Sample 1) When a Merge Request has been accepted into master:

  • If the day isn't "Monday through Thursday", require manual deployment
  • If the days are M-Th, auto-deploy

Sample 2) When a Merge Request has been accepted into master:

  • If a merge request contains label: complicated the Merge Request should require manual deployment using GitLab Deployment Management (e.g. the configuration optionwhen: manual)
  • If a merge request does not contain label, the Merge Request should be automatically deployed upon Build Success

Sample 3) When a Merge Request has been accepted into master:

  • If ref is not the latest, require manual deployment
  • If the commit ref is the latest, continue with Continuous Deployment

Sample 4) (concept behind this is to avoid having multiple pending / running builds for the same branch, e.g. master)

When a commit is pushed to origin/<branch>:

  • If sha is the latest, run build
  • If sha is not the latest version, cancel build

(might relate to https://gitlab.com/gitlab-org/gitlab-ce/issues/8998)

Proposal

Allow scripts to run within the when configuration.

deploy:production:
  stage: deploy
  script: REF=$CI_BUILD_REF BRANCH=$CI_BUILD_REF_NAME bundle exec cap production deploy
  when:
    - bin/external_bash_script
  only:
    - master
  environment:
    name: production
    url: http://www.example.com

Links / references

https://docs.gitlab.com/ce/ci/yaml/#manual-actions

Edited Jul 27, 2020 by Jason Yavorsky
Assignee Loading
Time tracking Loading