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
dcf09d11
Commit
dcf09d11
authored
Aug 31, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement `failure_reason` on `ci_builds`
parent
597bc292
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
61 additions
and
6 deletions
+61
-6
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
app/models/commit_status.rb
app/models/commit_status.rb
+18
-0
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+1
-1
app/workers/stuck_ci_jobs_worker.rb
app/workers/stuck_ci_jobs_worker.rb
+1
-1
db/migrate/20170830125940_add_failure_reason_to_ci_builds.rb
db/migrate/20170830125940_add_failure_reason_to_ci_builds.rb
+9
-0
db/schema.rb
db/schema.rb
+2
-1
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+1
-1
lib/api/runner.rb
lib/api/runner.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+20
-0
spec/requests/api/commit_statuses_spec.rb
spec/requests/api/commit_statuses_spec.rb
+3
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+2
-0
spec/services/projects/update_pages_service_spec.rb
spec/services/projects/update_pages_service_spec.rb
+1
-0
spec/workers/stuck_ci_jobs_worker_spec.rb
spec/workers/stuck_ci_jobs_worker_spec.rb
+1
-0
No files found.
app/models/ci/build.rb
View file @
dcf09d11
...
@@ -103,7 +103,7 @@ module Ci
...
@@ -103,7 +103,7 @@ module Ci
end
end
end
end
before_transition
any
=>
[
:failed
]
do
|
build
|
before_transition
any
=>
[
:failed
]
do
|
build
,
transition
|
next
if
build
.
retries_max
.
zero?
next
if
build
.
retries_max
.
zero?
if
build
.
retries_count
<
build
.
retries_max
if
build
.
retries_count
<
build
.
retries_max
...
...
app/models/commit_status.rb
View file @
dcf09d11
...
@@ -38,6 +38,19 @@ class CommitStatus < ActiveRecord::Base
...
@@ -38,6 +38,19 @@ class CommitStatus < ActiveRecord::Base
scope
:retried_ordered
,
->
{
retried
.
ordered
.
includes
(
project: :namespace
)
}
scope
:retried_ordered
,
->
{
retried
.
ordered
.
includes
(
project: :namespace
)
}
scope
:after_stage
,
->
(
index
)
{
where
(
'stage_idx > ?'
,
index
)
}
scope
:after_stage
,
->
(
index
)
{
where
(
'stage_idx > ?'
,
index
)
}
enum
failure_reason:
{
no_error:
nil
,
failed_by_script:
1
,
# TODO: Not used. Should we expand pipeline as well?
failed_by_missing_dependency:
2
,
# This will be done in the next MR.
failed_by_system:
3
,
# TODO: Not used. What's this state?
failed_by_failed_job_state:
4
,
failed_by_out_of_quota:
5
,
# TODO: Only EE. How can we detect?
failed_by_stuck_and_timeout:
6
,
failed_by_no_runner:
7
,
# TODO: Not used. How can we detect?
failed_by_api:
8
,
failed_by_page:
9
}
state_machine
:status
do
state_machine
:status
do
event
:process
do
event
:process
do
transition
[
:skipped
,
:manual
]
=>
:created
transition
[
:skipped
,
:manual
]
=>
:created
...
@@ -79,6 +92,11 @@ class CommitStatus < ActiveRecord::Base
...
@@ -79,6 +92,11 @@ class CommitStatus < ActiveRecord::Base
commit_status
.
finished_at
=
Time
.
now
commit_status
.
finished_at
=
Time
.
now
end
end
before_transition
any
=>
:failed
do
|
commit_status
,
transition
|
failure_reason
=
transition
.
args
.
first
commit_status
.
failure_reason
=
failure_reason
end
after_transition
do
|
commit_status
,
transition
|
after_transition
do
|
commit_status
,
transition
|
next
if
transition
.
loopback?
next
if
transition
.
loopback?
...
...
app/services/projects/update_pages_service.rb
View file @
dcf09d11
...
@@ -53,7 +53,7 @@ module Projects
...
@@ -53,7 +53,7 @@ module Projects
log_error
(
"Projects::UpdatePagesService:
#{
message
}
"
)
log_error
(
"Projects::UpdatePagesService:
#{
message
}
"
)
@status
.
allow_failure
=
!
latest?
@status
.
allow_failure
=
!
latest?
@status
.
description
=
message
@status
.
description
=
message
@status
.
drop
@status
.
drop
(
:page
)
super
super
end
end
...
...
app/workers/stuck_ci_jobs_worker.rb
View file @
dcf09d11
...
@@ -53,7 +53,7 @@ class StuckCiJobsWorker
...
@@ -53,7 +53,7 @@ class StuckCiJobsWorker
def
drop_build
(
type
,
build
,
status
,
timeout
)
def
drop_build
(
type
,
build
,
status
,
timeout
)
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
,
3
)
do
|
b
|
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
,
3
)
do
|
b
|
b
.
drop
b
.
drop
(
:stuck_and_timeout
)
end
end
end
end
end
end
db/migrate/20170830125940_add_failure_reason_to_ci_builds.rb
0 → 100644
View file @
dcf09d11
class
AddFailureReasonToCiBuilds
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:ci_builds
,
:failure_reason
,
:integer
end
end
db/schema.rb
View file @
dcf09d11
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201708
24162758
)
do
ActiveRecord
::
Schema
.
define
(
version:
201708
30125940
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -247,6 +247,7 @@ ActiveRecord::Schema.define(version: 20170824162758) do
...
@@ -247,6 +247,7 @@ ActiveRecord::Schema.define(version: 20170824162758) do
t
.
boolean
"retried"
t
.
boolean
"retried"
t
.
integer
"stage_id"
t
.
integer
"stage_id"
t
.
boolean
"protected"
t
.
boolean
"protected"
t
.
integer
"failure_reason"
end
end
add_index
"ci_builds"
,
[
"auto_canceled_by_id"
],
name:
"index_ci_builds_on_auto_canceled_by_id"
,
using: :btree
add_index
"ci_builds"
,
[
"auto_canceled_by_id"
],
name:
"index_ci_builds_on_auto_canceled_by_id"
,
using: :btree
...
...
lib/api/commit_statuses.rb
View file @
dcf09d11
...
@@ -103,7 +103,7 @@ module API
...
@@ -103,7 +103,7 @@ module API
when
'success'
when
'success'
status
.
success!
status
.
success!
when
'failed'
when
'failed'
status
.
drop!
status
.
drop!
(
:api
)
when
'canceled'
when
'canceled'
status
.
cancel!
status
.
cancel!
else
else
...
...
lib/api/runner.rb
View file @
dcf09d11
...
@@ -127,7 +127,7 @@ module API
...
@@ -127,7 +127,7 @@ module API
when
'success'
when
'success'
job
.
success
job
.
success
when
'failed'
when
'failed'
job
.
drop
job
.
drop
(
:failed_job_state
)
end
end
end
end
...
...
spec/models/ci/build_spec.rb
View file @
dcf09d11
...
@@ -1710,4 +1710,24 @@ describe Ci::Build do
...
@@ -1710,4 +1710,24 @@ describe Ci::Build do
end
end
end
end
end
end
describe
'set failure_reason when drop'
do
let
(
:build
)
{
create
(
:ci_build
,
:created
)
}
before
do
build
.
drop!
(
reason
)
end
context
'when failure_reason is nil'
do
let
(
:reason
)
{
}
it
{
expect
(
build
).
to
be_no_error
}
end
context
'when failure_reason is script_error'
do
let
(
:reason
)
{
:script_error
}
it
{
expect
(
build
).
to
be_failed_by_missing_dependency
}
end
end
end
end
spec/requests/api/commit_statuses_spec.rb
View file @
dcf09d11
...
@@ -142,6 +142,9 @@ describe API::CommitStatuses do
...
@@ -142,6 +142,9 @@ describe API::CommitStatuses do
expect
(
json_response
[
'ref'
]).
not_to
be_empty
expect
(
json_response
[
'ref'
]).
not_to
be_empty
expect
(
json_response
[
'target_url'
]).
to
be_nil
expect
(
json_response
[
'target_url'
]).
to
be_nil
expect
(
json_response
[
'description'
]).
to
be_nil
expect
(
json_response
[
'description'
]).
to
be_nil
if
status
==
'failed'
expect
(
CommitStatus
.
find
(
json_response
[
'id'
])).
to
be_failed_by_api
end
end
end
end
end
end
end
...
...
spec/requests/api/runner_spec.rb
View file @
dcf09d11
...
@@ -627,12 +627,14 @@ describe API::Runner do
...
@@ -627,12 +627,14 @@ describe API::Runner do
update_job
(
state:
'success'
)
update_job
(
state:
'success'
)
expect
(
job
.
reload
.
status
).
to
eq
'success'
expect
(
job
.
reload
.
status
).
to
eq
'success'
expect
(
job
).
to
be_no_error
end
end
it
'mark job as failed'
do
it
'mark job as failed'
do
update_job
(
state:
'failed'
)
update_job
(
state:
'failed'
)
expect
(
job
.
reload
.
status
).
to
eq
'failed'
expect
(
job
.
reload
.
status
).
to
eq
'failed'
expect
(
job
).
to
be_failed_by_failed_job_state
end
end
end
end
...
...
spec/services/projects/update_pages_service_spec.rb
View file @
dcf09d11
...
@@ -116,6 +116,7 @@ describe Projects::UpdatePagesService do
...
@@ -116,6 +116,7 @@ describe Projects::UpdatePagesService do
expect
(
deploy_status
.
description
)
expect
(
deploy_status
.
description
)
.
to
match
(
/artifacts for pages are too large/
)
.
to
match
(
/artifacts for pages are too large/
)
expect
(
deploy_status
).
to
be_failed_by_page
end
end
end
end
...
...
spec/workers/stuck_ci_jobs_worker_spec.rb
View file @
dcf09d11
...
@@ -20,6 +20,7 @@ describe StuckCiJobsWorker do
...
@@ -20,6 +20,7 @@ describe StuckCiJobsWorker do
it
'changes status'
do
it
'changes status'
do
worker
.
perform
worker
.
perform
is_expected
.
to
eq
(
'failed'
)
is_expected
.
to
eq
(
'failed'
)
expect
(
job
).
to
be_failed_by_stuck_and_timeout
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