Skip to content
Snippets Groups Projects

Add auto-cancel for pending pipelines on branch, if they are not HEAD

Compare and Show latest version
1 file
+ 24
10
Compare changes
  • Side-by-side
  • Inline
@@ -21,6 +21,12 @@ def execute_service(after: project.commit.id, message: 'Message', ref: 'refs/hea
@@ -21,6 +21,12 @@ def execute_service(after: project.commit.id, message: 'Message', ref: 'refs/hea
context 'valid params' do
context 'valid params' do
let(:pipeline) { execute_service }
let(:pipeline) { execute_service }
 
let(:pipeline_on_previous_commit) do
 
execute_service(
 
after: previous_commit_sha_from_ref('master')
 
)
 
end
 
it { expect(pipeline).to be_kind_of(Ci::Pipeline) }
it { expect(pipeline).to be_kind_of(Ci::Pipeline) }
it { expect(pipeline).to be_valid }
it { expect(pipeline).to be_valid }
it { expect(pipeline).to eq(project.pipelines.last) }
it { expect(pipeline).to eq(project.pipelines.last) }
@@ -29,20 +35,10 @@ def execute_service(after: project.commit.id, message: 'Message', ref: 'refs/hea
@@ -29,20 +35,10 @@ def execute_service(after: project.commit.id, message: 'Message', ref: 'refs/hea
it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) }
it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) }
context 'auto-cancel enabled' do
context 'auto-cancel enabled' do
let(:pipeline_on_previous_commit) do
execute_service(
after: previous_commit_sha_from_ref('master')
)
end
before do
before do
project.update(auto_cancel_pending_pipelines: 'enabled')
project.update(auto_cancel_pending_pipelines: 'enabled')
end
end
def previous_commit_sha_from_ref(ref)
project.commit(ref).parent.sha
end
it 'does not cancel HEAD pipeline' do
it 'does not cancel HEAD pipeline' do
pipeline
pipeline
pipeline_on_previous_commit
pipeline_on_previous_commit
@@ -81,6 +77,24 @@ def previous_commit_sha_from_ref(ref)
@@ -81,6 +77,24 @@ def previous_commit_sha_from_ref(ref)
expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by_id: nil)
expect(pending_pipeline.reload).to have_attributes(status: 'pending', auto_canceled_by_id: nil)
end
end
end
end
 
 
context 'auto-cancel disabled' do
 
before do
 
project.update(auto_cancel_pending_pipelines: 'disabled')
 
end
 
 
it 'does not auto cancel pending non-HEAD pipelines' do
 
pipeline_on_previous_commit
 
pipeline
 
 
expect(pipeline_on_previous_commit.reload)
 
.to have_attributes(status: 'pending', auto_canceled_by_id: nil)
 
end
 
end
 
 
def previous_commit_sha_from_ref(ref)
 
project.commit(ref).parent.sha
 
end
end
end
context "skip tag if there is no build for it" do
context "skip tag if there is no build for it" do
Loading