summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-07-20 19:15:32 +0900
committerShinya Maeda <shinya@gitlab.com>2018-07-20 19:15:32 +0900
commit746c260d5e4ae4604a3b072e9c58e6c2ee1e114e (patch)
tree8b0edd17bf1dae4fc9487544a5503d3bc173f9a7
parent82a8d55742f73a43c5281af8245f5e5873985344 (diff)
parentbfdf565800b58e838a760aa01d2fadb64e2d768f (diff)
downloadgitlab-ce-746c260d5e4ae4604a3b072e9c58e6c2ee1e114e.tar.gz
Merge branch 'artifact-format-v2' into artifact-format-v2-with-parser
-rw-r--r--app/models/ci/build.rb16
-rw-r--r--app/models/ci/job_artifact.rb26
-rw-r--r--app/models/concerns/artifact_migratable.rb2
-rw-r--r--app/presenters/ci/build_presenter.rb45
-rw-r--r--db/migrate/20180705160945_add_file_format_to_ci_job_artifacts.rb2
-rw-r--r--lib/api/entities.rb8
-rw-r--r--lib/api/runner.rb4
-rw-r--r--lib/gitlab/ci/config/entry/artifacts.rb48
-rw-r--r--lib/gitlab/ci/config/entry/commands.rb13
-rw-r--r--lib/gitlab/ci/config/entry/reports.rb12
-rw-r--r--lib/gitlab/ci/trace.rb30
-rw-r--r--spec/factories/ci/builds.rb9
-rw-r--r--spec/factories/ci/job_artifacts.rb4
-rw-r--r--spec/fixtures/junit.xml.gzbin0 -> 568 bytes
-rw-r--r--spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/commands_spec.rb3
-rw-r--r--spec/models/ci/build_spec.rb4
-rw-r--r--spec/models/ci/job_artifact_spec.rb28
-rw-r--r--spec/presenters/ci/build_presenter_spec.rb8
-rw-r--r--spec/requests/api/jobs_spec.rb4
-rw-r--r--spec/requests/api/runner_spec.rb56
-rw-r--r--spec/services/ci/retry_build_service_spec.rb4
22 files changed, 248 insertions, 80 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 0078ae052d2..1b749dd67d0 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -391,6 +391,10 @@ module Ci
trace.exist?
end
+ def has_test_reports?
+ job_artifacts.test_reports.any?
+ end
+
def has_old_trace?
old_trace.present?
end
@@ -453,22 +457,26 @@ module Ci
end
def erase_artifacts!
- remove_legacy_artifacts_file! if legacy_artifacts_file
- remove_legacy_artifacts_metadata! if legacy_artifacts_metadata
- job_artifacts.destroy_all
+ remove_artifacts_file!
+ remove_artifacts_metadata!
save
end
+ def erase_test_reports!
+ job_artifacts.test_reports.destroy_all
+ end
+
def erase(opts = {})
return false unless erasable?
erase_artifacts!
+ erase_test_reports!
erase_trace!
update_erased!(opts[:erased_by])
end
def erasable?
- complete? && (artifacts? || has_trace?)
+ complete? && (artifacts? || has_test_reports? || has_trace?)
end
def erased?
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb
index 414b6c4be89..c76895c8d7d 100644
--- a/app/models/ci/job_artifact.rb
+++ b/app/models/ci/job_artifact.rb
@@ -9,7 +9,8 @@ module Ci
mount_uploader :file, JobArtifactUploader
- validates :file_format, presence: true, on: :create
+ validates :file_format, presence: true, unless: :ignore_schema, on: :create
+ validate :valid_file_format?, unless: :ignore_schema, on: :create
before_save :set_size, if: :file_changed?
after_save :update_project_statistics_after_save, if: :size_changed?
after_destroy :update_project_statistics_after_destroy, unless: :project_destroyed?
@@ -18,15 +19,26 @@ module Ci
scope :with_files_stored_locally, -> { where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]) }
+ scope :test_reports, -> do
+ types = self.file_types.select { |k, _| TEST_REPORT_FILE_TYPES.include?(k) }.values
+
+ where(file_type: types)
+ end
+
delegate :exists?, :open, to: :file
enum file_type: {
archive: 1,
- archive_metadata: 2,
+ metadata: 2,
trace: 3,
junit: 4
}
+ GENERAL_ARCHIVE_FILE_TYPE = 'archive'.freeze
+ TEST_REPORT_FILE_TYPES = %w[junit].freeze
+ DEFAULT_FILE_NAMES = { junit: 'junit.xml' }.freeze
+ TYPE_AND_FORMAT_PAIRS = { archive: :zip, metadata: :gzip, trace: :raw, junit: :gzip }.freeze
+
enum file_format: {
raw: 1,
zip: 2,
@@ -37,6 +49,16 @@ module Ci
gzip: Gitlab::Ci::Build::Artifacts::GzipFileAdapter
}
+ def valid_file_format?
+ unless TYPE_AND_FORMAT_PAIRS[self.file_type&.to_sym] == self.file_format&.to_sym
+ errors.add(:file_format, 'Invalid file format with specified file type')
+ end
+ end
+
+ def ignore_schema
+ ActiveRecord::Migrator.current_version <= ::Gitlab::Ci::Trace::ARCHIVE_LEGACY_TRACES_MIGRATION_VERSION
+ end
+
def update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
diff --git a/app/models/concerns/artifact_migratable.rb b/app/models/concerns/artifact_migratable.rb
index ca9aba5ac3a..ff52ca64459 100644
--- a/app/models/concerns/artifact_migratable.rb
+++ b/app/models/concerns/artifact_migratable.rb
@@ -7,7 +7,7 @@ module ArtifactMigratable
end
def artifacts_metadata
- job_artifacts_archive_metadata&.file || legacy_artifacts_metadata
+ job_artifacts_metadata&.file || legacy_artifacts_metadata
end
def artifacts?
diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb
index 6b52c91749f..5e3829693d1 100644
--- a/app/presenters/ci/build_presenter.rb
+++ b/app/presenters/ci/build_presenter.rb
@@ -34,14 +34,31 @@ module Ci
end
def config_artifacts
- list = []
+ [].tap do |list|
+ next unless options[:artifacts]
- options.dig(:artifacts).try do |artifacts|
- list << config_artifacts_reports(artifacts.delete(:reports)) if artifacts.dig(:reports)
- list << config_artifacts_archive(artifacts) if artifacts.dig(:paths)
- end
+ options[:artifacts].except(:reports).try do |archive|
+ ::Gitlab::Ci::Config::Entry::Artifacts.new(archive).present_for_runner.tap do |runner_config|
+ unless ::Gitlab::Ci::Config::Entry::ArtifactsForRunner.new(runner_config).valid?
+ raise ArgumentError, 'General artifact config for runner is not valid'
+ end
+
+ list << runner_config
+ end
+ end
+
+ options[:artifacts].dig(:reports).try do |reports|
+ ::Gitlab::Ci::Config::Entry::Reports.new(reports).present_for_runner.tap do |runner_configs|
+ list << runner_configs.map do |runner_config|
+ unless ::Gitlab::Ci::Config::Entry::ArtifactsForRunner.new(runner_config).valid?
+ raise ArgumentError, 'Report-type artifact config for runner is not valid'
+ end
- list.flatten
+ runner_config
+ end
+ end
+ end
+ end.flatten
end
private
@@ -53,21 +70,5 @@ module Ci
def detailed_status
@detailed_status ||= subject.detailed_status(user)
end
-
- def config_artifacts_archive(artifacts)
- artifacts.merge(type: :archive, format: :zip)
- end
-
- def config_artifacts_reports(reports)
- list = []
-
- list << config_artifacts_reports_junit(reports.dig(:junit)) if reports.dig(:junit)
-
- list
- end
-
- def config_artifacts_reports_junit(junit)
- { name: 'junit.xml', paths: junit, type: :junit, format: :gzip, when: :always }
- end
end
end
diff --git a/db/migrate/20180705160945_add_file_format_to_ci_job_artifacts.rb b/db/migrate/20180705160945_add_file_format_to_ci_job_artifacts.rb
index 9867506a925..2f0be9fa5db 100644
--- a/db/migrate/20180705160945_add_file_format_to_ci_job_artifacts.rb
+++ b/db/migrate/20180705160945_add_file_format_to_ci_job_artifacts.rb
@@ -1,5 +1,7 @@
# rubocop:disable all
class AddFileFormatToCiJobArtifacts < ActiveRecord::Migration
+ DOWNTIME = false
+
def change
add_column :ci_job_artifacts, :file_format, :integer, limit: 2
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8c671e7badd..f5db70a9466 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1072,7 +1072,7 @@ module API
end
class Job < JobBasic
- expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts_archive? }
+ expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :runner, with: Runner
expose :artifacts_expire_at
end
@@ -1228,8 +1228,8 @@ module API
class Artifacts < Grape::Entity
expose :name, :untracked, :paths, :when, :expire_in
- expose :type, as: :artifact_type
- expose :format, as: :artifact_format
+ expose :artifact_type
+ expose :artifact_format
end
class Cache < Grape::Entity
@@ -1242,7 +1242,7 @@ module API
class Dependency < Grape::Entity
expose :id, :name, :token
- expose :artifacts_file, using: JobArtifactFile, if: ->(job, _) { job.artifacts_archive? }
+ expose :artifacts_file, using: JobArtifactFile, if: ->(job, _) { job.artifacts? }
end
class Response < Grape::Entity
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index 03bfcd50be0..a7d3db57bac 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -236,7 +236,7 @@ module API
optional :artifact_type, type: String, desc: %q(The type of artifact),
default: 'archive', values: Ci::JobArtifact.file_types.keys
optional :artifact_format, type: String, desc: %q(The format of artifact),
- default: 'zip', values: Ci::JobArtifact.file_formats.keys
+ default: 'zip', values: Ci::JobArtifact.file_formats.keys
optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse))
optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse))
optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse))
@@ -275,7 +275,7 @@ module API
job.job_artifacts.build(
project: job.project,
file: metadata,
- file_type: "#{params['artifact_type']}_metadata",
+ file_type: :metadata,
file_format: :gzip,
file_sha256: metadata.sha256,
expire_in: expire_in)
diff --git a/lib/gitlab/ci/config/entry/artifacts.rb b/lib/gitlab/ci/config/entry/artifacts.rb
index ca80dbd85a2..b276f7ec8d1 100644
--- a/lib/gitlab/ci/config/entry/artifacts.rb
+++ b/lib/gitlab/ci/config/entry/artifacts.rb
@@ -37,9 +37,55 @@ module Gitlab
helpers :reports
def value
- @config[:reports] = reports_value
+ @config[:reports] = reports_value if @config.key?(:reports)
@config
end
+
+ def present_for_runner
+ @config.merge(artifact_type: :archive, artifact_format: :zip)
+ end
+ end
+
+ class ArtifactsForRunner < Node
+ include Validatable
+ include Attributable
+
+ ALLOWED_KEYS = %i[name untracked paths when expire_in artifact_type artifact_format].freeze
+
+ attributes ALLOWED_KEYS
+
+ validations do
+ validates :config, type: Hash
+ validates :config, allowed_keys: ALLOWED_KEYS
+ validates :artifact_type, type: Symbol
+ validates :artifact_format, type: Symbol
+
+ with_options if: :general_artifact? do
+ with_options allow_nil: true do
+ validates :name, type: String
+ validates :untracked, boolean: true
+ validates :paths, array_of_strings: true
+ validates :when, inclusion: { in: %w[on_success on_failure always] }
+ validates :expire_in, duration: true
+ end
+ end
+
+ with_options if: :report_artifact? do
+ validates :name, type: String
+ validates :untracked, presence: false
+ validates :paths, array_of_strings: true
+ validates :when, inclusion: { in: %w[always] }
+ validates :expire_in, presence: false
+ end
+ end
+
+ def general_artifact?
+ ::Ci::JobArtifact::GENERAL_ARCHIVE_FILE_TYPE == @config[:artifact_type]
+ end
+
+ def report_artifact?
+ ::Ci::JobArtifact::TEST_REPORT_FILE_TYPES.include?(@config[:artifact_type])
+ end
end
end
end
diff --git a/lib/gitlab/ci/config/entry/commands.rb b/lib/gitlab/ci/config/entry/commands.rb
index 65d19db249c..9f66f11be9b 100644
--- a/lib/gitlab/ci/config/entry/commands.rb
+++ b/lib/gitlab/ci/config/entry/commands.rb
@@ -9,18 +9,7 @@ module Gitlab
include Validatable
validations do
- include LegacyValidationHelpers
-
- validate do
- unless string_or_array_of_strings?(config)
- errors.add(:config,
- 'should be a string or an array of strings')
- end
- end
-
- def string_or_array_of_strings?(field)
- validate_string(field) || validate_array_of_strings(field)
- end
+ validates :config, array_of_strings_or_string: true
end
def value
diff --git a/lib/gitlab/ci/config/entry/reports.rb b/lib/gitlab/ci/config/entry/reports.rb
index 5963f3eb90c..fcc28a42521 100644
--- a/lib/gitlab/ci/config/entry/reports.rb
+++ b/lib/gitlab/ci/config/entry/reports.rb
@@ -25,6 +25,18 @@ module Gitlab
def value
@config.transform_values { |v| Array(v) }
end
+
+ def present_for_runner
+ @config.map do |k, v|
+ {
+ name: ::Ci::JobArtifact::DEFAULT_FILE_NAMES[k.to_sym],
+ paths: v,
+ artifact_type: k.to_sym,
+ artifact_format: :gzip,
+ when: 'always'
+ }
+ end
+ end
end
end
end
diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb
index 769d998227c..ee0adc790d8 100644
--- a/lib/gitlab/ci/trace.rb
+++ b/lib/gitlab/ci/trace.rb
@@ -162,14 +162,32 @@ module Gitlab
end
end
+ ##
+ # NOTE:
+ # In 11.0, we shipped a post migration to archive legacy traces. In the migration script,
+ # `Trace#archive!` method was directly used for simplying the migration logic.
+ # In 11.2, we created a new column in `ci_job_artifacts` table and started saving a value to the column,
+ # however, this brought up a problem that if users bump their GitLab instance version from 10.7 to 11.2,
+ # then their legacy trace migrations are going to require the new column to be present, even though 11.2's migration has not run yet.
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20390#note_89084352
+ ARCHIVE_LEGACY_TRACES_MIGRATION_VERSION = 20180529152628
+
def create_build_trace!(job, path)
File.open(path) do |stream|
- job.create_job_artifacts_trace!(
- project: job.project,
- file_type: :trace,
- file_format: :raw,
- file: stream,
- file_sha256: Digest::SHA256.file(path).hexdigest)
+ if ActiveRecord::Migrator.current_version <= ARCHIVE_LEGACY_TRACES_MIGRATION_VERSION
+ job.create_job_artifacts_trace!(
+ project: job.project,
+ file_type: :trace,
+ file: stream,
+ file_sha256: Digest::SHA256.file(path).hexdigest)
+ else
+ job.create_job_artifacts_trace!(
+ project: job.project,
+ file_type: :trace,
+ file_format: :raw,
+ file: stream,
+ file_sha256: Digest::SHA256.file(path).hexdigest)
+ end
end
end
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 99f14a08039..8bd1f1ae4e0 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -182,7 +182,14 @@ FactoryBot.define do
trait :artifacts do
after(:create) do |build|
create(:ci_job_artifact, :archive, job: build, expire_at: build.artifacts_expire_at)
- create(:ci_job_artifact, :archive_metadata, job: build, expire_at: build.artifacts_expire_at)
+ create(:ci_job_artifact, :metadata, job: build, expire_at: build.artifacts_expire_at)
+ build.reload
+ end
+ end
+
+ trait :test_reports do
+ after(:create) do |build|
+ create(:ci_job_artifact, :junit, job: build)
build.reload
end
end
diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb
index 631e92f7338..a6a87782fe7 100644
--- a/spec/factories/ci/job_artifacts.rb
+++ b/spec/factories/ci/job_artifacts.rb
@@ -24,8 +24,8 @@ FactoryBot.define do
end
end
- trait :archive_metadata do
- file_type :archive_metadata
+ trait :metadata do
+ file_type :metadata
file_format :gzip
after(:build) do |artifact, _|
diff --git a/spec/fixtures/junit.xml.gz b/spec/fixtures/junit.xml.gz
new file mode 100644
index 00000000000..88b7de6fa61
--- /dev/null
+++ b/spec/fixtures/junit.xml.gz
Binary files differ
diff --git a/spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb b/spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb
index 877c061d11b..a9b07eb3122 100644
--- a/spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb
+++ b/spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 20180529152628 do
+describe Gitlab::BackgroundMigration::ArchiveLegacyTraces, :migration, schema: 20180705160945 do
include TraceHelpers
let(:namespaces) { table(:namespaces) }
diff --git a/spec/lib/gitlab/ci/config/entry/commands_spec.rb b/spec/lib/gitlab/ci/config/entry/commands_spec.rb
index afa4a089418..84734b06caa 100644
--- a/spec/lib/gitlab/ci/config/entry/commands_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/commands_spec.rb
@@ -41,8 +41,7 @@ describe Gitlab::Ci::Config::Entry::Commands do
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
- .to include 'commands config should be a ' \
- 'string or an array of strings'
+ .to include 'commands config should be an array of strings or string'
end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 7c3ddab1751..ee923374480 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -861,7 +861,7 @@ describe Ci::Build do
let!(:build) { create(:ci_build, :success, :artifacts) }
before do
- build.job_artifacts_metadata.destroy
+ build.remove_artifacts_metadata!
end
describe '#erase' do
@@ -930,7 +930,7 @@ describe Ci::Build do
let!(:build) { create(:ci_build, :success, :legacy_artifacts) }
before do
- build.remove_legacy_artifacts_metadata!
+ build.remove_artifacts_metadata!
end
describe '#erase' do
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index 594211c288f..4474df73434 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -90,25 +90,35 @@ describe Ci::JobArtifact do
describe 'validates file format' do
subject { artifact.valid? }
- let(:artifact) { build(:ci_job_artifact, file_format: file_format) }
-
- context 'when file format is present' do
- let(:file_format) { :raw }
+ context 'when archive type with zip format' do
+ let(:artifact) { build(:ci_job_artifact, :archive, file_format: :zip) }
it { is_expected.to be_truthy }
end
- context 'when file format is not defined' do
- let(:file_format) { :new_format }
+ context 'when archive type with gzip format' do
+ let(:artifact) { build(:ci_job_artifact, :archive, file_format: :gzip) }
+
+ it { is_expected.to be_falsy }
+ end
+
+ context 'when archive type without format specification' do
+ let(:artifact) { build(:ci_job_artifact, :archive, file_format: nil) }
- it { expect { subject }.to raise_error(ArgumentError) }
+ it { is_expected.to be_falsy }
end
- context 'when file format is not present' do
- let(:file_format) { nil }
+ context 'when junit type with zip format' do
+ let(:artifact) { build(:ci_job_artifact, :junit, file_format: :zip) }
it { is_expected.to be_falsy }
end
+
+ context 'when junit type with gzip format' do
+ let(:artifact) { build(:ci_job_artifact, :junit, file_format: :gzip) }
+
+ it { is_expected.to be_truthy }
+ end
end
describe '#file' do
diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb
index 78d00c4e14a..8f1763193d7 100644
--- a/spec/presenters/ci/build_presenter_spec.rb
+++ b/spec/presenters/ci/build_presenter_spec.rb
@@ -258,7 +258,7 @@ describe Ci::BuildPresenter do
let(:build) { create(:ci_build, options: { artifacts: { paths: ['sample.txt'] } } ) }
it 'presents artifacts hash' do
- expect(presenter.config_artifacts).to include({ type: :archive, format: :zip, paths: ['sample.txt'] })
+ expect(presenter.config_artifacts).to include({ artifact_type: :archive, artifact_format: :zip, paths: ['sample.txt'] })
end
end
@@ -266,7 +266,7 @@ describe Ci::BuildPresenter do
let(:build) { create(:ci_build, options: { artifacts: { reports: { junit: ['junit.xml'] } } } ) }
it 'presents artifacts hash' do
- expect(presenter.config_artifacts).to include({ type: :junit, format: :gzip, paths: ['junit.xml'] })
+ expect(presenter.config_artifacts).to include({ name: 'junit.xml', artifact_type: :junit, artifact_format: :gzip, paths: ['junit.xml'], when: 'always' })
end
end
@@ -275,8 +275,8 @@ describe Ci::BuildPresenter do
it 'presents artifacts hash' do
expect(presenter.config_artifacts).to include(
- { type: :junit, format: :gzip, paths: ['junit.xml'] },
- { type: :archive, format: :zip, paths: ['sample.txt'] })
+ { name: 'junit.xml', artifact_type: :junit, artifact_format: :gzip, paths: ['junit.xml'], when: 'always' },
+ { artifact_type: :archive, artifact_format: :zip, paths: ['sample.txt'] })
end
end
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb
index 7d1a5c12805..46d9a363b02 100644
--- a/spec/requests/api/jobs_spec.rb
+++ b/spec/requests/api/jobs_spec.rb
@@ -654,13 +654,15 @@ describe API::Jobs do
end
context 'job is erasable' do
- let(:job) { create(:ci_build, :trace_artifact, :artifacts, :success, project: project, pipeline: pipeline) }
+ let(:job) { create(:ci_build, :trace_artifact, :artifacts, :test_reports, :success, project: project, pipeline: pipeline) }
it 'erases job content' do
expect(response).to have_gitlab_http_status(201)
+ expect(job.job_artifacts.count).to eq(0)
expect(job.trace.exist?).to be_falsy
expect(job.artifacts_file.exists?).to be_falsy
expect(job.artifacts_metadata.exists?).to be_falsy
+ expect(job.has_test_reports?).to be_falsy
end
it 'updates job' do
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index 401ba7959bc..0f41e46cdd5 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -424,7 +424,9 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
'untracked' => false,
'paths' => %w(out/),
'when' => 'always',
- 'expire_in' => '7d' }]
+ 'expire_in' => '7d',
+ "artifact_type" => "archive",
+ "artifact_format" => "zip" }]
end
let(:expected_cache) do
@@ -1380,7 +1382,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
let(:stored_metadata_file) { job.reload.artifacts_metadata.file }
let(:stored_artifacts_size) { job.reload.artifacts_size }
let(:stored_artifacts_sha256) { job.reload.job_artifacts_archive.file_sha256 }
- let(:stored_metadata_sha256) { job.reload.job_artifacts_archive_metadata.file_sha256 }
+ let(:stored_metadata_sha256) { job.reload.job_artifacts_metadata.file_sha256 }
before do
post(api("/jobs/#{job.id}/artifacts"), post_data, headers_with_token)
@@ -1420,6 +1422,56 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
end
+
+ context 'when artifact_type is archive' do
+ context 'when artifact_format is zip' do
+ let(:params) { { artifact_type: :archive, artifact_format: :zip } }
+
+ it 'stores junit test report' do
+ upload_artifacts(file_upload, headers_with_token, params)
+
+ expect(response).to have_gitlab_http_status(201)
+ expect(job.reload.job_artifacts_archive).not_to be_nil
+ end
+ end
+
+ context 'when artifact_format is gzip' do
+ let(:params) { { artifact_type: :archive, artifact_format: :gzip } }
+
+ it 'returns an error' do
+ upload_artifacts(file_upload, headers_with_token, params)
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(job.reload.job_artifacts_archive).to be_nil
+ end
+ end
+ end
+
+ context 'when artifact_type is junit' do
+ context 'when artifact_format is gzip' do
+ let(:file_upload) { fixture_file_upload('spec/fixtures/junit.xml.gz') }
+ let(:params) { { artifact_type: :junit, artifact_format: :gzip } }
+
+ it 'stores junit test report' do
+ upload_artifacts(file_upload, headers_with_token, params)
+
+ expect(response).to have_gitlab_http_status(201)
+ expect(job.reload.job_artifacts_junit).not_to be_nil
+ end
+ end
+
+ context 'when artifact_format is raw' do
+ let(:file_upload) { fixture_file_upload('spec/fixtures/junit.xml.gz') }
+ let(:params) { { artifact_type: :junit, artifact_format: :raw } }
+
+ it 'returns an error' do
+ upload_artifacts(file_upload, headers_with_token, params)
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(job.reload.job_artifacts_junit).to be_nil
+ end
+ end
+ end
end
context 'when artifacts are being stored outside of tmp path' do
diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb
index 41899740081..18d52082399 100644
--- a/spec/services/ci/retry_build_service_spec.rb
+++ b/spec/services/ci/retry_build_service_spec.rb
@@ -24,7 +24,7 @@ describe Ci::RetryBuildService do
artifacts_file artifacts_metadata artifacts_size created_at
updated_at started_at finished_at queued_at erased_by
erased_at auto_canceled_by job_artifacts job_artifacts_archive
- job_artifacts_archive_metadata job_artifacts_trace].freeze
+ job_artifacts_metadata job_artifacts_trace job_artifacts_junit].freeze
IGNORE_ACCESSORS =
%i[type lock_version target_url base_tags trace_sections
@@ -38,7 +38,7 @@ describe Ci::RetryBuildService do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
let(:build) do
- create(:ci_build, :failed, :artifacts, :expired, :erased,
+ create(:ci_build, :failed, :artifacts, :test_reports, :expired, :erased,
:queued, :coverage, :tags, :allowed_to_fail, :on_tag,
:triggered, :trace_artifact, :teardown_environment,
description: 'my-job', stage: 'test', stage_id: stage.id,