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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
52b34969
Commit
52b34969
authored
Feb 28, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add build policy for pipeline expressions
parent
1926eca0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
lib/gitlab/ci/build/policy/variables.rb
lib/gitlab/ci/build/policy/variables.rb
+22
-0
spec/lib/gitlab/ci/build/policy/variables_spec.rb
spec/lib/gitlab/ci/build/policy/variables_spec.rb
+41
-0
No files found.
lib/gitlab/ci/build/policy/variables.rb
0 → 100644
View file @
52b34969
module
Gitlab
module
Ci
module
Build
module
Policy
class
Variables
<
Policy
::
Specification
def
initialize
(
expressions
)
@expressions
=
Array
(
expressions
)
end
def
satisfied_by?
(
pipeline
)
statements
=
@expressions
.
map
do
|
statement
|
::
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
.
new
(
statement
,
pipeline
)
end
statements
.
any?
{
|
statement
|
statement
.
truthful?
}
end
end
end
end
end
end
spec/lib/gitlab/ci/build/policy/variables_spec.rb
0 → 100644
View file @
52b34969
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Policy
::
Variables
do
let
(
:pipeline
)
{
build
(
:ci_pipeline
,
ref:
'master'
)
}
before
do
pipeline
.
variables
.
build
(
key:
'CI_PROJECT_NAME'
,
value:
''
)
end
describe
'#satisfied_by?'
do
it
'is satisfied by a defined and existing variable'
do
policy
=
described_class
.
new
([
'$CI_PROJECT_ID'
,
'$UNDEFINED'
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
)
end
it
'is not satisfied by an overriden empty variable'
do
policy
=
described_class
.
new
([
'$CI_PROJECT_NAME'
])
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
)
end
it
'is satisfied by a truthy pipeline expression'
do
policy
=
described_class
.
new
([
%($CI_PIPELINE_SOURCE == "#{pipeline.source}")
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
)
end
it
'is not satisfied by a falsy pipeline expression'
do
policy
=
described_class
.
new
([
%($CI_PIPELINE_SOURCE == "invalid source")
])
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
)
end
it
'is satisfied by a truthy expression using undefined variable'
do
policy
=
described_class
.
new
([
'$UNDEFINED'
,
'$UNDEFINED == null'
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
)
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