diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-01-25 18:50:56 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-02-06 15:50:07 +0900 |
commit | 63a9d582aa88d774af5eff124b693df6271ae7bc (patch) | |
tree | 626d1569a1a5a980473abad552832608b6cf56fc | |
parent | 84bda43a3c0ce13a436748d0bc0ea943f6ebccb3 (diff) | |
download | gitlab-ce-63a9d582aa88d774af5eff124b693df6271ae7bc.tar.gz |
Trace as artifacts
-rw-r--r-- | app/models/ci/build.rb | 1 | ||||
-rw-r--r-- | app/models/ci/job_artifact.rb | 5 | ||||
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 4 | ||||
-rw-r--r-- | lib/api/runner.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/ci/trace.rb | 22 |
5 files changed, 33 insertions, 10 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 78906e7a968..20534b8eed0 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -21,6 +21,7 @@ module Ci has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_one :job_artifacts_archive, -> { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id + has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id # The "environment" field for builds is a String, and is the unexpanded name def persisted_environment diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index 84fc6863567..0a599f72bc7 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -9,9 +9,12 @@ module Ci mount_uploader :file, JobArtifactUploader + delegate :open, :exists?, to: :file + enum file_type: { archive: 1, - metadata: 2 + metadata: 2, + trace: 3 } def self.artifacts_size_for(project) diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 0abb462ab7d..8766db94079 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -13,6 +13,10 @@ class JobArtifactUploader < GitlabUploader dynamic_segment end + def open + File.open(path, "rb") + end + private def dynamic_segment diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 1f80646a2ea..bab9d263e8d 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -120,7 +120,16 @@ module API put '/:id' do job = authenticate_job! - job.trace.set(params[:trace]) if params[:trace] + if params[:trace] + # Overwrite live-trace by full-trace + job.trace.set(params[:trace]) + + # Move full-trace to JobArtifactUploader#default_path + job.build_job_artifacts_trace( + project: job.project, + file_type: :trace, + file: UploadedFile.new(job.trace.current_path, 'trace.log')) + end Gitlab::Metrics.add_event(:update_build, project: job.project.full_path) diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index baf55b1fa07..a6827d7a38a 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -52,12 +52,14 @@ module Gitlab end def exist? - current_path.present? || old_trace.present? + trace_artifact&.exists? || current_path.present? || old_trace.present? end def read stream = Gitlab::Ci::Trace::Stream.new do - if current_path + if trace_artifact + trace_artifact.open + elsif current_path File.open(current_path, "rb") elsif old_trace StringIO.new(old_trace) @@ -104,12 +106,6 @@ module Gitlab end end - def current_path - @current_path ||= paths.find do |trace_path| - File.exist?(trace_path) - end - end - def paths [ default_path, @@ -117,6 +113,12 @@ module Gitlab ].compact end + def current_path + @current_path ||= paths.find do |trace_path| + File.exist?(trace_path) + end + end + def default_directory File.join( Settings.gitlab_ci.builds_path, @@ -137,6 +139,10 @@ module Gitlab "#{job.id}.log" ) if job.project&.ci_id end + + def trace_artifact + job.job_artifacts_trace + end end end end |