summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-07-18 11:03:00 +0000
committerRémy Coutable <remy@rymai.me>2016-07-18 11:03:00 +0000
commit550466dd34cb97d4704644b292ab1ef271222981 (patch)
tree2fc73ab4389f3cf4c1a51f4ed22ef33dad902265 /lib
parent2556d6d34761b6cfc4a81cfcb8f9c4a2fea114dc (diff)
parentffea9c46000ade225852ee32e90cb8ad0f4f8316 (diff)
downloadgitlab-ce-550466dd34cb97d4704644b292ab1ef271222981.tar.gz
Merge branch 'store-variables-and-when-in-builds-table' into 'master'
Store when and yaml variables in builds table ## What does this MR do? Stores `when` and `yaml_variables` in `ci_builds` table. ## Why was this MR needed? This is done in order to simplify the code responsible for creating a pipeline builds. ## What are the relevant issue numbers? This made as a pre-step for https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5295. ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - [x] API support added - Tests - [x] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5296
Diffstat (limited to 'lib')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb53
1 files changed, 38 insertions, 15 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 01ef13df57a..a48dc542b14 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -31,28 +31,34 @@ 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, job|
+ build_job(name, job)
+ 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, job|
+ build_job(name, job)
+ end
+ end
- job[:variables] || []
+ def builds
+ @jobs.map do |name, job|
+ build_job(name, job)
+ end
end
private
@@ -95,11 +101,10 @@ module Ci
commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
tag_list: job[:tags] || [],
name: name,
- only: job[:only],
- except: job[:except],
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,
@@ -111,6 +116,24 @@ module Ci
}
end
+ 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!
@jobs.each do |name, job|
validate_job!(name, job)