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
ca639c9b
Commit
ca639c9b
authored
Nov 19, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to retry failed or canceled builds and fix cancel running specs failure
parent
92a83aae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
9 deletions
+69
-9
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+8
-6
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+1
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+60
-3
No files found.
app/models/ci/pipeline.rb
View file @
ca639c9b
...
...
@@ -161,9 +161,7 @@ module Ci
end
def
retryable?
builds
.
latest
.
any?
do
|
build
|
(
build
.
failed?
||
build
.
canceled?
)
&&
build
.
retryable?
end
builds
.
latest
.
failed_or_canceled
.
any?
(
&
:retryable?
)
end
def
cancelable?
...
...
@@ -171,12 +169,16 @@ module Ci
end
def
cancel_running
statuses
.
cancelable
.
each
(
&
:cancel
)
Gitlab
::
OptimisticLocking
.
retry_lock
(
statuses
.
cancelable
)
do
|
cancelable
|
cancelable
.
each
(
&
:cancel
)
end
end
def
retry_failed
(
user
)
builds
.
latest
.
failed
.
select
(
&
:retryable?
).
each
do
|
build
|
Ci
::
Build
.
retry
(
build
,
user
)
Gitlab
::
OptimisticLocking
.
retry_lock
(
builds
.
latest
.
failed_or_canceled
)
do
|
failed
|
failed
.
select
(
&
:retryable?
).
each
do
|
build
|
Ci
::
Build
.
retry
(
build
,
user
)
end
end
end
...
...
app/models/concerns/has_status.rb
View file @
ca639c9b
...
...
@@ -73,6 +73,7 @@ module HasStatus
scope
:skipped
,
->
{
where
(
status:
'skipped'
)
}
scope
:running_or_pending
,
->
{
where
(
status:
[
:running
,
:pending
])
}
scope
:finished
,
->
{
where
(
status:
[
:success
,
:failed
,
:canceled
])
}
scope
:failed_or_canceled
,
->
{
where
(
status:
[
:failed
,
:canceled
])
}
scope
:cancelable
,
->
do
where
(
status:
[
:running
,
:pending
,
:created
])
...
...
spec/models/ci/pipeline_spec.rb
View file @
ca639c9b
...
...
@@ -455,17 +455,74 @@ describe Ci::Pipeline, models: true do
end
describe
'#cancel_running'
do
let
(
:latest_status
)
{
pipeline
.
statuses
.
pluck
(
:status
)
}
context
'when there is a running external job and created build'
do
before
do
create
(
:ci_build
,
:running
,
pipeline:
pipeline
)
create
(
:generic_commit_status
,
:running
,
pipeline:
pipeline
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
)
pipeline
.
cancel_running
end
it
'cancels both jobs'
do
expect
(
pipeline
.
statuses
.
pluck
(
:status
)).
to
contain_exactly
(
'canceled'
,
'canceled'
)
expect
(
latest_status
).
to
contain_exactly
(
'canceled'
,
'canceled'
)
end
end
context
'when builds are in different stages'
do
before
do
create
(
:ci_build
,
:running
,
stage_idx:
0
,
pipeline:
pipeline
)
create
(
:ci_build
,
:running
,
stage_idx:
1
,
pipeline:
pipeline
)
pipeline
.
cancel_running
end
it
'cancels both jobs'
do
expect
(
latest_status
).
to
contain_exactly
(
'canceled'
,
'canceled'
)
end
end
end
describe
'#retry_failed'
do
let
(
:latest_status
)
{
pipeline
.
statuses
.
latest
.
pluck
(
:status
)
}
context
'when there is a failed build and failed external status'
do
before
do
create
(
:ci_build
,
:failed
,
name:
'build'
,
pipeline:
pipeline
)
create
(
:generic_commit_status
,
:failed
,
name:
'jenkins'
,
pipeline:
pipeline
)
pipeline
.
retry_failed
(
nil
)
end
it
'retries only build'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'failed'
)
end
end
context
'when builds are in different stages'
do
before
do
create
(
:ci_build
,
:failed
,
name:
'build'
,
stage_idx:
0
,
pipeline:
pipeline
)
create
(
:ci_build
,
:failed
,
name:
'jenkins'
,
stage_idx:
1
,
pipeline:
pipeline
)
pipeline
.
retry_failed
(
nil
)
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'pending'
)
end
end
context
'when there are canceled and failed'
do
before
do
create
(
:ci_build
,
:failed
,
name:
'build'
,
stage_idx:
0
,
pipeline:
pipeline
)
create
(
:ci_build
,
:canceled
,
name:
'jenkins'
,
stage_idx:
1
,
pipeline:
pipeline
)
pipeline
.
retry_failed
(
nil
)
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'pending'
)
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