Commit 2c6cbd9b authored by Kamil Trzciński's avatar Kamil Trzciński

Require other stages than .pre and .post

Do not create pipeline that only
contains .pre, .post stages.

These pipelines alone does not make
sense.
parent 157a4aba
---
title: Require other stages than .pre and .post
merge_request: 23629
author:
type: fixed
......@@ -17,7 +17,7 @@ module Gitlab
#
pipeline.stages = @command.stage_seeds.map(&:to_resource)
if pipeline.stages.none?
if stage_names.empty?
return error('No stages / jobs for this pipeline.')
end
......@@ -31,6 +31,15 @@ module Gitlab
def break?
pipeline.errors.any?
end
private
def stage_names
# We filter out `.pre/.post` stages, as they alone are not considered
# a complete pipeline:
# https://gitlab.com/gitlab-org/gitlab/issues/198518
pipeline.stages.map(&:name) - ::Gitlab::Ci::Config::EdgeStagesInjector::EDGES
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Ci::CreatePipelineService do
context '.pre/.post stages' do
let_it_be(:user) { create(:admin) }
let_it_be(:project) { create(:project, :repository, creator: user) }
let(:source) { :push }
let(:service) { described_class.new(project, user, { ref: ref }) }
let(:pipeline) { service.execute(source) }
let(:config) do
<<~YAML
validate:
stage: .pre
script: echo Hello World
build:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == "master"
script: echo Hello World
notify:
stage: .post
script: echo Hello World
YAML
end
before do
stub_ci_pipeline_yaml_file(config)
end
context 'when pipeline contains a build except .pre/.post' do
let(:ref) { 'refs/heads/master' }
it 'creates a pipeline' do
expect(pipeline).to be_persisted
expect(pipeline.stages.map(&:name)).to contain_exactly(
*%w(.pre build .post))
expect(pipeline.builds.map(&:name)).to contain_exactly(
*%w(validate build notify))
end
end
context 'when pipeline does not contain any other build except .pre/.post' do
let(:ref) { 'refs/heads/feature' }
it 'does not create a pipeline' do
expect(pipeline).not_to be_persisted
# we can validate a list of stages, as they are assigned
# but not persisted
expect(pipeline.stages.map(&:name)).to contain_exactly(
*%w(.pre .post))
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment