summaryrefslogtreecommitdiff
path: root/app/models/ci
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2019-07-29 07:43:10 +0000
committerPhil Hughes <me@iamphill.com>2019-07-29 07:43:10 +0000
commita5aa40c5fe93dc3daba8a578f4c09c4e443fcbec (patch)
tree34eb74d209b1919f78ce70d89ee0900cd2602780 /app/models/ci
parent946f7c0687760ec49aca582a329d0ec3c7ac3037 (diff)
downloadgitlab-ce-a5aa40c5fe93dc3daba8a578f4c09c4e443fcbec.tar.gz
Add Job specific variables
Adds Job specific variables to facilitate specifying variables when running manual jobs.
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/build.rb7
-rw-r--r--app/models/ci/job_variable.rb14
2 files changed, 19 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index da70cb9a9a7..07813e03f3a 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -40,6 +40,7 @@ module Ci
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy, inverse_of: :job # rubocop:disable Cop/ActiveRecordDependent
+ has_many :job_variables, class_name: 'Ci::JobVariable', foreign_key: :job_id
Ci::JobArtifact.file_types.each do |key, value|
has_one :"job_artifacts_#{key}", -> { where(file_type: value) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
@@ -48,6 +49,7 @@ module Ci
has_one :runner_session, class_name: 'Ci::BuildRunnerSession', validate: true, inverse_of: :build
accepts_nested_attributes_for :runner_session
+ accepts_nested_attributes_for :job_variables
delegate :url, to: :runner_session, prefix: true, allow_nil: true
delegate :terminal_specification, to: :runner_session, allow_nil: true
@@ -331,10 +333,10 @@ module Ci
end
# rubocop: disable CodeReuse/ServiceClass
- def play(current_user)
+ def play(current_user, job_variables_attributes = nil)
Ci::PlayBuildService
.new(project, current_user)
- .execute(self)
+ .execute(self, job_variables_attributes)
end
# rubocop: enable CodeReuse/ServiceClass
@@ -432,6 +434,7 @@ module Ci
Gitlab::Ci::Variables::Collection.new
.concat(persisted_variables)
.concat(scoped_variables)
+ .concat(job_variables)
.concat(persisted_environment_variables)
.to_runner_variables
end
diff --git a/app/models/ci/job_variable.rb b/app/models/ci/job_variable.rb
new file mode 100644
index 00000000000..862a0bc1299
--- /dev/null
+++ b/app/models/ci/job_variable.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Ci
+ class JobVariable < ApplicationRecord
+ extend Gitlab::Ci::Model
+ include NewHasVariable
+
+ belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
+
+ alias_attribute :secret_value, :value
+
+ validates :key, uniqueness: { scope: :job_id }
+ end
+end