summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-20 10:44:01 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-20 10:44:01 +0200
commit795c9f2241db7967d03f7792431fe65013a5dd0f (patch)
tree220a27d93fca929b01980abd6f1d77759859351d /lib/ci
parentbb8bf6427d80cb4858318a44e395a2d1cd9115b7 (diff)
parent79b02e40e5842540ceff4454f6c2c51f13fc081c (diff)
downloadgitlab-ce-795c9f2241db7967d03f7792431fe65013a5dd0f.tar.gz
Merge branch 'master' into refactor/ci-config-move-job-entries
* master: (321 commits) Fix the Sentry spam from CSP violations by disabling it. Limit git rev-list output count to one in forced push check Ensure Owners are included in the scope for authorized_projects Fix alignment of icons on project page Fix ci_status_helper_spec to look for new SVGs use 2.0.5, actually (2.0.4 was a bad release) upgrade rouge to 2.0.4 Fix help page paths to make sure shortcuts and the UI help page work. fixes an issue cause by a bad merge Vertically align status icon within table Add new icons for every CI status Add global style for running icon Align running icon in merge request Add new running icon; add a bunch of styles to get svg to match existing fa icons Improve code design Fix broken builds_for_ref Move when tests before to make it no conflict with manual-actions Use value of `yaml_variables` and `when` from config_processor if undefined Add CHANGELOG entry CHANGELOG item ... Conflicts: lib/ci/gitlab_ci_yaml_processor.rb spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
Diffstat (limited to 'lib/ci')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb97
1 files changed, 63 insertions, 34 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index aa2f7743a5e..013813ef00b 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -19,28 +19,62 @@ module Ci
raise ValidationError, e.message
end
- def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
- builds.select do |build|
- build[:stage] == stage &&
- process?(build[:only], build[:except], ref, tag, trigger_request)
+ def jobs_for_ref(ref, tag = false, trigger_request = nil)
+ @jobs.select do |_, job|
+ process?(job[:only], job[:except], ref, tag, trigger_request)
end
end
- def builds
- @jobs.map do |name, job|
- build_job(name, job)
+ def jobs_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
+ jobs_for_ref(ref, tag, trigger_request).select do |_, job|
+ job[:stage] == stage
end
end
- def global_variables
- @variables
+ def builds_for_ref(ref, tag = false, trigger_request = nil)
+ jobs_for_ref(ref, tag, trigger_request).map do |name, _|
+ build_attributes(name)
+ end
end
- def job_variables(name)
- job = @jobs[name.to_sym]
- return [] unless job
+ def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
+ jobs_for_stage_and_ref(stage, ref, tag, trigger_request).map do |name, _|
+ build_attributes(name)
+ end
+ end
- job[:variables] || []
+ def builds
+ @jobs.map do |name, _|
+ build_attributes(name)
+ end
+ end
+
+ def build_attributes(name)
+ job = @jobs[name.to_sym] || {}
+ {
+ stage_idx: @stages.index(job[:stage]),
+ stage: job[:stage],
+ ##
+ # Refactoring note:
+ # - before script behaves differently than after script
+ # - after script returns an array of commands
+ # - before script should be a concatenated command
+ commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
+ tag_list: job[:tags] || [],
+ name: job[:name],
+ allow_failure: job[:allow_failure] || false,
+ when: job[:when] || 'on_success',
+ environment: job[:environment],
+ yaml_variables: yaml_variables(name),
+ options: {
+ image: job[:image] || @image,
+ services: job[:services] || @services,
+ artifacts: job[:artifacts],
+ cache: job[:cache] || @cache,
+ dependencies: job[:dependencies],
+ after_script: job[:after_script] || @after_script,
+ }.compact
+ }
end
private
@@ -67,27 +101,22 @@ module Ci
end
end
- def build_job(name, job)
- {
- stage_idx: @stages.index(job[:stage]),
- stage: job[:stage],
- commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
- tag_list: job[:tags] || [],
- name: job[:name],
- only: job[:only],
- except: job[:except],
- allow_failure: job[:allow_failure] || false,
- when: job[:when] || 'on_success',
- environment: job[:environment],
- options: {
- image: job[:image] || @image,
- services: job[:services] || @services,
- artifacts: job[:artifacts],
- cache: job[:cache] || @cache,
- dependencies: job[:dependencies],
- after_script: job[:after_script] || @after_script,
- }.compact
- }
+ def yaml_variables(name)
+ variables = global_variables.merge(job_variables(name))
+ variables.map do |key, value|
+ { key: key, value: value, public: true }
+ end
+ end
+
+ def global_variables
+ @variables || {}
+ end
+
+ def job_variables(name)
+ job = @jobs[name.to_sym]
+ return {} unless job
+
+ job[:variables] || {}
end
def validate_job!(name, job)