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
2624b4d0
Commit
2624b4d0
authored
Jan 12, 2022
by
Alishan Ladhani
Committed by
Shinya Maeda
Jan 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow enqueuing builds that are waiting for deployment approval
parent
9e971c74
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
3 deletions
+36
-3
app/models/ci/build.rb
app/models/ci/build.rb
+5
-1
app/models/deployment.rb
app/models/deployment.rb
+4
-0
ee/app/services/deployments/approval_service.rb
ee/app/services/deployments/approval_service.rb
+1
-0
ee/spec/services/deployments/approval_service_spec.rb
ee/spec/services/deployments/approval_service_spec.rb
+4
-2
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+22
-0
No files found.
app/models/ci/build.rb
View file @
2624b4d0
...
...
@@ -268,6 +268,10 @@ module Ci
!
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
)
...
...
@@ -424,7 +428,7 @@ module Ci
end
def
playable?
action?
&&
!
archived?
&&
(
manual?
||
scheduled?
||
retryable?
)
action?
&&
!
archived?
&&
(
manual?
||
scheduled?
||
retryable?
)
&&
!
waiting_for_deployment_approval?
end
def
waiting_for_deployment_approval?
...
...
app/models/deployment.rb
View file @
2624b4d0
...
...
@@ -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
...
...
ee/app/services/deployments/approval_service.rb
View file @
2624b4d0
...
...
@@ -32,6 +32,7 @@ module Deployments
if
approval
.
rejected?
deployment
.
deployable
.
drop!
(
:deployment_rejected
)
elsif
deployment
.
pending_approval_count
<=
0
deployment
.
unblock!
deployment
.
deployable
.
enqueue!
end
end
...
...
ee/spec/services/deployments/approval_service_spec.rb
View file @
2624b4d0
...
...
@@ -103,9 +103,11 @@ RSpec.describe Deployments::ApprovalService do
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
...
...
spec/models/ci/build_spec.rb
View file @
2624b4d0
...
...
@@ -2468,6 +2468,16 @@ RSpec.describe Ci::Build do
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
...
...
@@ -3792,6 +3802,18 @@ RSpec.describe Ci::Build do
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
)
}
...
...
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