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
Jérome Perrin
gitlab-ce
Commits
19ef4083
Commit
19ef4083
authored
Feb 13, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a separate CI/CD pipeline retry service class
parent
1be454e7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
1 deletion
+73
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-1
app/services/ci/retry_pipeline_service.rb
app/services/ci/retry_pipeline_service.rb
+22
-0
spec/services/ci/retry_pipeline_service_spec.rb
spec/services/ci/retry_pipeline_service_spec.rb
+48
-0
No files found.
app/models/ci/pipeline.rb
View file @
19ef4083
...
@@ -234,7 +234,9 @@ module Ci
...
@@ -234,7 +234,9 @@ module Ci
end
end
def
mark_as_processable_after_stage
(
stage_idx
)
def
mark_as_processable_after_stage
(
stage_idx
)
builds
.
skipped
.
where
(
'stage_idx > ?'
,
stage_idx
).
find_each
(
&
:process
)
builds
.
skipped
.
where
(
'stage_idx > ?'
,
stage_idx
)
.
find_each
(
&
:process
)
end
end
def
latest?
def
latest?
...
...
app/services/ci/retry_pipeline_service.rb
0 → 100644
View file @
19ef4083
module
Ci
class
RetryPipelineService
include
Gitlab
::
Allowable
def
initialize
(
pipeline
,
user
)
@pipeline
=
pipeline
@user
=
user
end
def
execute
unless
can?
(
@user
,
:update_pipeline
,
@pipeline
)
raise
Gitlab
::
Access
::
AccessDeniedError
end
@pipeline
.
stages
.
each
do
|
stage
|
stage
.
builds
.
failed_or_canceled
.
find_each
do
|
build
|
Ci
::
Build
.
retry
(
build
,
@user
)
end
end
end
end
end
spec/services/ci/retry_pipeline_service_spec.rb
0 → 100644
View file @
19ef4083
require
'spec_helper'
describe
Ci
::
RetryPipelineService
,
'#execute'
,
:services
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
pipeline
,
user
)
}
context
'when user has ability to modify pipeline'
do
let
(
:user
)
{
create
(
:admin
)
}
context
'when there are failed builds in the last stage'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :success
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :failed
,
stage_num:
1
)
create_build
(
name:
'rspec 3'
,
status: :canceled
,
stage_num:
1
)
end
it
'enqueues all builds in the last stage'
do
service
.
execute
expect
(
build
(
'rspec 2'
)).
to
be_pending
expect
(
build
(
'rspec 3'
)).
to
be_pending
end
end
end
context
'when user is not allowed to retry pipeline'
do
it
'raises an error'
do
expect
{
service
.
execute
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
end
end
def
build
(
name
)
pipeline
.
statuses
.
find_by
(
name:
name
)
end
def
create_build
(
name
:,
status
:,
stage_num
:)
create
(
:ci_build
,
name:
name
,
status:
status
,
stage:
"stage_
#{
stage_num
}
"
,
stage_idx:
stage_num
,
pipeline:
pipeline
)
do
|
build
|
pipeline
.
update_status
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