diff --git a/gems/gitlab-housekeeper/bin/gitlab-housekeeper b/gems/gitlab-housekeeper/bin/gitlab-housekeeper index fb169d337616aad882643ed19df31b3831ae9b23..5748dd2decb33c4aa8d26943b066a94523394602 100755 --- a/gems/gitlab-housekeeper/bin/gitlab-housekeeper +++ b/gems/gitlab-housekeeper/bin/gitlab-housekeeper @@ -3,6 +3,18 @@ require "optparse" require 'gitlab/housekeeper' +REQUIRED_CONFIG_KEYS = [ + 'HOUSEKEEPER_GITLAB_API_TOKEN', + 'HOUSEKEEPER_TARGET_PROJECT_ID' +].freeze + +def validate_configuration! + REQUIRED_CONFIG_KEYS.each do |required_key| + # fetch will fail with an error if the key isn't found. + ENV.fetch(required_key) + end +end + options = {} OptionParser.new do |opts| @@ -33,4 +45,7 @@ OptionParser.new do |opts| end end.parse! +# We do not want to validate configuration on dry runs +validate_configuration! unless options[:dry_run] + Gitlab::Housekeeper::Runner.new(**options).run