Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d6a2d655
Commit
d6a2d655
authored
Dec 13, 2019
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify behaviour of rules
This makes the logic when to remove only/except much simpler
parent
de5dd327
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
55 deletions
+54
-55
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
+12
-5
lib/gitlab/ci/config/entry/job.rb
lib/gitlab/ci/config/entry/job.rb
+12
-5
lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
+13
-5
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+1
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-0
spec/services/ci/create_pipeline_service/rules_spec.rb
spec/services/ci/create_pipeline_service/rules_spec.rb
+15
-40
No files found.
ee/lib/ee/gitlab/ci/config/entry/bridge.rb
View file @
d6a2d655
...
@@ -65,6 +65,7 @@ module EE
...
@@ -65,6 +65,7 @@ module EE
entry
:only
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
entry
:only
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
description:
'Refs policy this job will be executed for.'
,
description:
'Refs policy this job will be executed for.'
,
default:
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
::
DEFAULT_ONLY
,
inherit:
false
inherit:
false
entry
:except
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
entry
:except
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
,
...
@@ -98,12 +99,18 @@ module EE
...
@@ -98,12 +99,18 @@ module EE
def
compose!
(
deps
=
nil
)
def
compose!
(
deps
=
nil
)
super
do
super
do
# If workflow:rules:, rules: and only: are undefined
has_workflow_rules
=
deps
&
.
workflow
&
.
has_rules?
# do create default `only:`
# If workflow:rules: or rules: are used
# they are considered not compatible
# with `only/except` defaults
#
#
# This is to make `only:` to be backward compatible
# Context: https://gitlab.com/gitlab-org/gitlab/merge_requests/21742
if
!
deps
&
.
workflow
&
.
has_rules?
&&
!
has_rules?
&&
!
only_defined?
if
has_rules?
||
has_workflow_rules
entry_create!
(
:only
,
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
::
DEFAULT_ONLY
)
# Remove only/except defaults
# defaults are not considered as defined
@entries
.
delete
(
:only
)
unless
only_defined?
@entries
.
delete
(
:except
)
unless
except_defined?
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/entry/job.rb
View file @
d6a2d655
...
@@ -120,6 +120,7 @@ module Gitlab
...
@@ -120,6 +120,7 @@ module Gitlab
entry
:only
,
Entry
::
Policy
,
entry
:only
,
Entry
::
Policy
,
description:
'Refs policy this job will be executed for.'
,
description:
'Refs policy this job will be executed for.'
,
default:
::
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
::
DEFAULT_ONLY
,
inherit:
false
inherit:
false
entry
:except
,
Entry
::
Policy
,
entry
:except
,
Entry
::
Policy
,
...
@@ -176,12 +177,18 @@ module Gitlab
...
@@ -176,12 +177,18 @@ module Gitlab
@entries
.
delete
(
:type
)
@entries
.
delete
(
:type
)
# If workflow:rules:, rules: and only: are undefined
has_workflow_rules
=
deps
&
.
workflow
&
.
has_rules?
# do create default `only:`
# If workflow:rules: or rules: are used
# they are considered not compatible
# with `only/except` defaults
#
#
# This is to make `only:` to be backward compatible
# Context: https://gitlab.com/gitlab-org/gitlab/merge_requests/21742
if
!
deps
&
.
workflow
&
.
has_rules?
&&
!
has_rules?
&&
!
only_defined?
if
has_rules?
||
has_workflow_rules
entry_create!
(
:only
,
Entry
::
Policy
::
DEFAULT_ONLY
)
# Remove only/except defaults
# defaults are not considered as defined
@entries
.
delete
(
:only
)
unless
only_defined?
@entries
.
delete
(
:except
)
unless
except_defined?
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/chain/evaluate_workflow_rules.rb
View file @
d6a2d655
...
@@ -9,7 +9,13 @@ module Gitlab
...
@@ -9,7 +9,13 @@ module Gitlab
include
Chain
::
Helpers
include
Chain
::
Helpers
def
perform!
def
perform!
return
unless
feature_enabled?
unless
feature_enabled?
if
has_workflow_rules?
error
(
"Workflow rules are disabled"
,
config_error:
true
)
end
return
end
unless
workflow_passed?
unless
workflow_passed?
error
(
'Pipeline filtered out by workflow rules.'
)
error
(
'Pipeline filtered out by workflow rules.'
)
...
@@ -17,15 +23,13 @@ module Gitlab
...
@@ -17,15 +23,13 @@ module Gitlab
end
end
def
break?
def
break?
return
false
unless
feature_enabled?
@pipeline
.
errors
.
any?
||
@pipeline
.
persisted?
!
workflow_passed?
end
end
private
private
def
feature_enabled?
def
feature_enabled?
Feature
.
enabled?
(
:workflow_rules
,
default_enabled:
true
)
Feature
.
enabled?
(
:workflow_rules
,
@pipeline
.
project
,
default_enabled:
true
)
end
end
def
workflow_passed?
def
workflow_passed?
...
@@ -44,6 +48,10 @@ module Gitlab
...
@@ -44,6 +48,10 @@ module Gitlab
@pipeline
,
yaml_variables:
workflow_config
[
:yaml_variables
])
@pipeline
,
yaml_variables:
workflow_config
[
:yaml_variables
])
end
end
def
has_workflow_rules?
workflow_config
[
:rules
].
present?
end
def
workflow_config
def
workflow_config
@command
.
config_processor
.
workflow_attributes
||
{}
@command
.
config_processor
.
workflow_attributes
||
{}
end
end
...
...
spec/models/ci/build_spec.rb
View file @
d6a2d655
...
@@ -2366,6 +2366,7 @@ describe Ci::Build do
...
@@ -2366,6 +2366,7 @@ describe Ci::Build do
{
key:
'CI_COMMIT_BEFORE_SHA'
,
value:
build
.
before_sha
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_BEFORE_SHA'
,
value:
build
.
before_sha
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_REF_NAME'
,
value:
build
.
ref
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_REF_NAME'
,
value:
build
.
ref
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_REF_SLUG'
,
value:
build
.
ref_slug
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_REF_SLUG'
,
value:
build
.
ref_slug
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_BRANCH'
,
value:
build
.
ref
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_MESSAGE'
,
value:
pipeline
.
git_commit_message
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_MESSAGE'
,
value:
pipeline
.
git_commit_message
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_TITLE'
,
value:
pipeline
.
git_commit_title
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_TITLE'
,
value:
pipeline
.
git_commit_title
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_DESCRIPTION'
,
value:
pipeline
.
git_commit_description
,
public:
true
,
masked:
false
},
{
key:
'CI_COMMIT_DESCRIPTION'
,
value:
pipeline
.
git_commit_description
,
public:
true
,
masked:
false
},
...
...
spec/models/ci/pipeline_spec.rb
View file @
d6a2d655
...
@@ -599,6 +599,7 @@ describe Ci::Pipeline, :mailer do
...
@@ -599,6 +599,7 @@ describe Ci::Pipeline, :mailer do
CI_COMMIT_BEFORE_SHA
CI_COMMIT_BEFORE_SHA
CI_COMMIT_REF_NAME
CI_COMMIT_REF_NAME
CI_COMMIT_REF_SLUG
CI_COMMIT_REF_SLUG
CI_COMMIT_BRANCH
CI_COMMIT_MESSAGE
CI_COMMIT_MESSAGE
CI_COMMIT_TITLE
CI_COMMIT_TITLE
CI_COMMIT_DESCRIPTION
CI_COMMIT_DESCRIPTION
...
...
spec/services/ci/create_pipeline_service/rules_spec.rb
View file @
d6a2d655
...
@@ -100,6 +100,17 @@ describe Ci::CreatePipelineService do
...
@@ -100,6 +100,17 @@ describe Ci::CreatePipelineService do
stub_ci_pipeline_yaml_file
(
config
)
stub_ci_pipeline_yaml_file
(
config
)
end
end
shared_examples
'workflow:rules feature disabled'
do
before
do
stub_feature_flags
(
workflow_rules:
false
)
end
it
'presents a message that rules are disabled'
do
expect
(
pipeline
.
errors
[
:base
]).
to
include
(
'Workflow rules are disabled'
)
expect
(
pipeline
).
to
be_persisted
end
end
context
'with a single regex-matching if: clause'
do
context
'with a single regex-matching if: clause'
do
let
(
:config
)
do
let
(
:config
)
do
<<-
EOY
<<-
EOY
...
@@ -231,16 +242,7 @@ describe Ci::CreatePipelineService do
...
@@ -231,16 +242,7 @@ describe Ci::CreatePipelineService do
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
).
not_to
be_persisted
end
end
context
'with workflow:rules shut off'
do
it_behaves_like
'workflow:rules feature disabled'
before
do
stub_feature_flags
(
workflow_rules:
false
)
end
it
'invalidates the pipeline with an empty jobs error'
do
expect
(
pipeline
.
errors
[
:base
]).
to
include
(
'No stages / jobs for this pipeline.'
)
expect
(
pipeline
).
not_to
be_persisted
end
end
end
end
context
'where workflow passes and the job passes'
do
context
'where workflow passes and the job passes'
do
...
@@ -251,16 +253,7 @@ describe Ci::CreatePipelineService do
...
@@ -251,16 +253,7 @@ describe Ci::CreatePipelineService do
expect
(
pipeline
).
to
be_persisted
expect
(
pipeline
).
to
be_persisted
end
end
context
'with workflow:rules shut off'
do
it_behaves_like
'workflow:rules feature disabled'
before
do
stub_feature_flags
(
workflow_rules:
false
)
end
it
'saves a pending pipeline'
do
expect
(
pipeline
).
to
be_pending
expect
(
pipeline
).
to
be_persisted
end
end
end
end
context
'where workflow fails and the job fails'
do
context
'where workflow fails and the job fails'
do
...
@@ -271,16 +264,7 @@ describe Ci::CreatePipelineService do
...
@@ -271,16 +264,7 @@ describe Ci::CreatePipelineService do
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
).
not_to
be_persisted
end
end
context
'with workflow:rules shut off'
do
it_behaves_like
'workflow:rules feature disabled'
before
do
stub_feature_flags
(
workflow_rules:
false
)
end
it
'invalidates the pipeline with an empty jobs error'
do
expect
(
pipeline
.
errors
[
:base
]).
to
include
(
'No stages / jobs for this pipeline.'
)
expect
(
pipeline
).
not_to
be_persisted
end
end
end
end
context
'where workflow fails and the job passes'
do
context
'where workflow fails and the job passes'
do
...
@@ -291,16 +275,7 @@ describe Ci::CreatePipelineService do
...
@@ -291,16 +275,7 @@ describe Ci::CreatePipelineService do
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
).
not_to
be_persisted
end
end
context
'with workflow:rules shut off'
do
it_behaves_like
'workflow:rules feature disabled'
before
do
stub_feature_flags
(
workflow_rules:
false
)
end
it
'saves a pending pipeline'
do
expect
(
pipeline
).
to
be_pending
expect
(
pipeline
).
to
be_persisted
end
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment