From 5b58da72d28361e659640a7c40372fbd72560e31 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 13 Apr 2023 20:30:02 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-9-stable-ee --- app/services/ci/retry_job_service.rb | 16 +++++++++++----- spec/services/ci/retry_job_service_spec.rb | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/services/ci/retry_job_service.rb b/app/services/ci/retry_job_service.rb index da0e80dfed7..e3cbba6de23 100644 --- a/app/services/ci/retry_job_service.rb +++ b/app/services/ci/retry_job_service.rb @@ -19,7 +19,7 @@ module Ci end # rubocop: disable CodeReuse/ActiveRecord - def clone!(job, variables: [], enqueue_if_actionable: false) + def clone!(job, variables: [], enqueue_if_actionable: false, start_pipeline: false) # Cloning a job requires a strict type check to ensure # the attributes being used for the clone are taken straight # from the model and not overridden by other abstractions. @@ -32,7 +32,11 @@ module Ci new_job.set_enqueue_immediately! end + start_pipeline_proc = -> { start_pipeline(job, new_job) } if start_pipeline + new_job.run_after_commit do + start_pipeline_proc&.call + ::Ci::CopyCrossDatabaseAssociationsService.new.execute(job, new_job) ::Deployments::CreateForBuildService.new.execute(new_job) @@ -59,15 +63,12 @@ module Ci def check_assignable_runners!(job); end def retry_job(job, variables: []) - clone!(job, variables: variables, enqueue_if_actionable: true).tap do |new_job| + clone!(job, variables: variables, enqueue_if_actionable: true, start_pipeline: true).tap do |new_job| check_assignable_runners!(new_job) if new_job.is_a?(Ci::Build) next if new_job.failed? ResetSkippedJobsService.new(project, current_user).execute(job) - - Ci::PipelineCreation::StartPipelineService.new(job.pipeline).execute - new_job.reset end end @@ -76,6 +77,11 @@ module Ci raise Gitlab::Access::AccessDeniedError, '403 Forbidden' end end + + def start_pipeline(job, new_job) + Ci::PipelineCreation::StartPipelineService.new(job.pipeline).execute + new_job.reset + end end end diff --git a/spec/services/ci/retry_job_service_spec.rb b/spec/services/ci/retry_job_service_spec.rb index 10acf032b1a..fed66bc535d 100644 --- a/spec/services/ci/retry_job_service_spec.rb +++ b/spec/services/ci/retry_job_service_spec.rb @@ -356,6 +356,21 @@ RSpec.describe Ci::RetryJobService, feature_category: :continuous_integration do it_behaves_like 'retries the job' + context 'automatic retryable build' do + let!(:auto_retryable_build) do + create(:ci_build, pipeline: pipeline, ci_stage: stage, user: user, options: { retry: 1 }) + end + + def drop_build! + auto_retryable_build.drop_with_exit_code!('test failure', 1) + end + + it 'creates a new build and enqueues BuildQueueWorker' do + expect { drop_build! }.to change { Ci::Build.count }.by(1) + .and change { BuildQueueWorker.jobs.count }.by(1) + end + end + context 'when there are subsequent jobs that are skipped' do let!(:subsequent_build) do create(:ci_build, :skipped, pipeline: pipeline, ci_stage: deploy_stage) -- cgit v1.2.1