From ed298c73a7da14a89cc6e7f7203658530204b8b8 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Wed, 12 May 2021 14:01:35 +0200 Subject: [PATCH] added more fine-grained control of custom_before_steps --- README.md | 2 +- moduleroot/.gitlab-ci.yml.erb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d830312..8945f7ee 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Gitlab CI uses a .gitlab-ci.yml file in the root of your repository tell Gitlab | custom_jobs |Define custom Gitlab CI jobs that will be executed. It is recommended that you use this option if you need customized Gitlab CI jobs. Please see the [.gitlab-ci.yml](https://docs.gitlab.com/ce/ci/yaml/README.html) docs for specifics.| | rubygems_mirror | Use a custom rubygems mirror url | | image |Define the Docker image to use, when using the Docker runner. Please see the [Using Docker images](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html) docs for specifics.| -| custom_before_steps |Allows you to pass additional steps to the GitLab CI before_script. Please see the [.gitlab-ci.yml](https://docs.gitlab.com/ce/ci/yaml/#before_script-and-after_script) docs for specifics.| +| custom_before_steps |Allows you to pass additional steps to the GitLab CI before_script. Please see the [.gitlab-ci.yml](https://docs.gitlab.com/ce/ci/yaml/#before_script-and-after_script) docs for specifics. If given as an array, the steps are executed _before_ the default steps of the before_script. If you want to have more control over the execution order of the steps, you can define a hash with a `before` and/or `after` key holding an array of steps to be executed before and after the default_script respectively.| | default_before_script |If false, removes the default `before_script` section. Useful if you need a customised Bundler install, or to remove Bundler entirely. If the key is unset the default behaviour is to add `before_script`.| |use_litmus| By default it is disabled. Set to `true` to configure travis to use Litmus testing tool for acceptance testing jobs with default values.| |litmus|Allows you to update default config values. Its sub keys are `provision_list`, `puppet_collection`, `ruby_version`, `install_wget` which are detailed below.| diff --git a/moduleroot/.gitlab-ci.yml.erb b/moduleroot/.gitlab-ci.yml.erb index e792cfa4..fcbdfcd2 100644 --- a/moduleroot/.gitlab-ci.yml.erb +++ b/moduleroot/.gitlab-ci.yml.erb @@ -50,8 +50,13 @@ default: <% if !configs.has_key?('default_before_script') || configs['default_before_script'] -%> before_script: &before_script <% if configs['custom_before_steps'] -%> -<% configs['custom_before_steps'].each do |step| -%> +<% if configs['custom_before_steps'].is_a? Array -%> +<% configs['custom_before_steps'] = { 'before' => configs['custom_before_steps'] } -%> +<% end -%> +<% if configs['custom_before_steps']['before'] -%> +<% configs['custom_before_steps']['before'].each do |step| -%> - <%= step %> +<% end -%> <% end -%> <% end -%> - bundle -v @@ -68,6 +73,11 @@ default: - gem --version - bundle -v - bundle install <%= configs['bundler_args'] %> +<% if configs['custom_before_steps'] and configs['custom_before_steps']['after'] -%> +<% configs['custom_before_steps']['after'].each do |step| -%> + - <%= step %> +<% end -%> +<% end -%> <% end -%> <% if configs['ruby_versions'] -%>