From 3c1c5230015b4e30fdd64f61ef8cb08ebc76fcbd Mon Sep 17 00:00:00 2001 From: David Hollinger Date: Thu, 3 May 2018 15:29:19 -0500 Subject: [PATCH] Update gitlab template --- README.md | 3 ++- config_defaults.yml | 10 +++++----- moduleroot/.gitlab-ci.yml.erb | 21 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 17c4fea3..41fb9be4 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,9 @@ Gitlab CI uses a .gitlab-ci.yml file in the root of your repository tell Gitlab Key | Description | | :------------- |:--------------| +| override |Defines whether your local `.sync.yml` will ignore the default values in pdk-templates. Defaults to `false`| | stages |Defines a job stage for when the CI/CD jobs will be executed in the pipeline.| -| env |Allows you to set any environment variables for the travis build. Currently includes setting the Puppet gem version.| +| variables |Allows you to set any environment variables for the travis build. Currently includes setting the Puppet gem version.| | bunder\_args |Define any arguments you want to pass through to bundler. The default is `--without system_tests` which avoids installing unnessesary gems.| | jobs |Define the actual Gitlab CI jobs that will be executed. Please see the [.gitlab-ci.yml](https://docs.gitlab.com/ce/ci/yaml/README.html) docs for specifics. Default jobs are created for `rubocop`, `syntax`, `metadata_lint`, and `rspec-puppet` tests on ruby versions `2.1.9` and `2.4.1`.| diff --git a/config_defaults.yml b/config_defaults.yml index e8aeb1b3..e192d6eb 100644 --- a/config_defaults.yml +++ b/config_defaults.yml @@ -553,9 +553,13 @@ Gemfile: # - gem: beaker-rspec # from_env: BEAKER_RSPEC_VERSION .gitlab-ci.yml: - stages: + defaults: + stages: - syntax - unit + variables: + PUPPET_GEM_VERSION: "~> 5.0" + bundler_args: --without system_tests jobs: rubocop_2.1.9: stage: syntax @@ -599,10 +603,6 @@ Gemfile: script: - bundle update - bundle exec rake spec - variables: - PUPPET_GEM_VERSION: "~> 4.0" - CHECK: spec - bundler_args: --without system_tests spec/default_facts.yml: concat_basedir: "/tmp" ipaddress: "172.16.254.254" diff --git a/moduleroot/.gitlab-ci.yml.erb b/moduleroot/.gitlab-ci.yml.erb index 00a04bb1..66156f82 100644 --- a/moduleroot/.gitlab-ci.yml.erb +++ b/moduleroot/.gitlab-ci.yml.erb @@ -1,9 +1,24 @@ --- +<% if !@configs['override'] && @configs.has_key('defaults') -%> +<% configs = @configs['defaults'] -%> +<% elsif @configs['override'] && @configs.has_key('custom') -%> +<% configs = @configs['custom'] -%> +<% else -%> +<% configs = @configs['defaults'] -%> +<% configs.merge!(@configs['custom']) unless @configs['custom'].nil? -%> +<% end -%> stages: -<% @configs['stages'].each do |stage| -%> +<% configs['stages'].each do |stage| -%> - <%= stage %> <% end -%> +<% if configs.has_key('variables') -%> +variables: +<% configs['variables'].each do |variable, value| -%> + <%= variable %>: <%= value %> +<% end -%> +<% end -%> + before_script: - bundle -v - rm Gemfile.lock || true @@ -11,9 +26,9 @@ before_script: - gem update bundler - gem --version - bundle -v - - bundle install <%= @configs['bundler_args'] %> + - bundle install <%= configs['bundler_args'] %> -<% @configs['jobs'].each do |job, params| -%> +<% configs['jobs'].each do |job, params| -%> <%= job %>: <%- params.keys.sort.each do |key| -%> <%- if params[key].is_a?(Array) -%>