Skip to content
Snippets Groups Projects
Commit 2624b4d0 authored by Alishan Ladhani's avatar Alishan Ladhani Committed by Shinya Maeda
Browse files

Disallow enqueuing builds that are waiting for deployment approval

parent 9e971c74
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -268,6 +268,10 @@ def with_preloads
!build.any_unmet_prerequisites? # If false is returned, it stops the transition
end
 
before_transition on: :enqueue do |build|
!build.waiting_for_deployment_approval? # If false is returned, it stops the transition
end
after_transition created: :scheduled do |build|
build.run_after_commit do
Ci::BuildScheduleWorker.perform_at(build.scheduled_at, build.id)
Loading
Loading
@@ -424,7 +428,7 @@ def archived?
end
 
def playable?
action? && !archived? && (manual? || scheduled? || retryable?)
action? && !archived? && (manual? || scheduled? || retryable?) && !waiting_for_deployment_approval?
end
 
def waiting_for_deployment_approval?
Loading
Loading
Loading
Loading
@@ -70,6 +70,10 @@ class Deployment < ApplicationRecord
transition created: :blocked
end
 
event :unblock do
transition blocked: :created
end
event :succeed do
transition any - [:success] => :success
end
Loading
Loading
Loading
Loading
@@ -32,6 +32,7 @@ def process_build!(deployment, approval)
if approval.rejected?
deployment.deployable.drop!(:deployment_rejected)
elsif deployment.pending_approval_count <= 0
deployment.unblock!
deployment.deployable.enqueue!
end
end
Loading
Loading
Loading
Loading
@@ -103,9 +103,11 @@
let(:required_approval_count) { 1 }
 
it 'enqueues the build' do
subject
expect { subject }.to change { deployment.deployable.status }.from('manual').to('pending')
end
 
expect(deployment.deployable.status).to eq('pending')
it 'unblocks the deployment' do
expect { subject }.to change { deployment.status }.from('blocked').to('created')
end
end
 
Loading
Loading
Loading
Loading
@@ -2468,6 +2468,16 @@
 
it { is_expected.not_to be_playable }
end
context 'when build is waiting for deployment approval' do
subject { build_stubbed(:ci_build, :manual, environment: 'production') }
before do
create(:deployment, :blocked, deployable: subject)
end
it { is_expected.not_to be_playable }
end
end
 
describe 'project settings' do
Loading
Loading
@@ -3792,6 +3802,18 @@
end
end
 
describe 'when the build is waiting for deployment approval' do
let(:build) { create(:ci_build, :manual, environment: 'production') }
before do
create(:deployment, :blocked, deployable: build)
end
it 'does not allow the build to be enqueued' do
expect { build.enqueue! }.to raise_error(StateMachines::InvalidTransition)
end
end
describe 'state transition: any => [:pending]' do
let(:build) { create(:ci_build, :created) }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment