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
Léo-Paul Géneau
gitlab-ce
Commits
623eb681
Commit
623eb681
authored
Nov 16, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new API endpoint - list jobs of a specified runner
parent
8e7e2aeb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
0 deletions
+161
-0
doc/api/runners.md
doc/api/runners.md
+51
-0
lib/api/runners.rb
lib/api/runners.rb
+18
-0
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+92
-0
No files found.
doc/api/runners.md
View file @
623eb681
...
@@ -215,6 +215,57 @@ DELETE /runners/:id
...
@@ -215,6 +215,57 @@ DELETE /runners/:id
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/runners/6"
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/runners/6"
```
```
## List runner's running jobs
List running jobs assigned to the specified Runner.
```
GET /runners/:id/jobs
```
| Attribute | Type | Required | Description |
|-----------|---------|----------|---------------------|
|
`id`
| integer | yes | The ID of a runner |
```
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/runners/1/jobs"
```
Example response:
```
json
[
{
"id"
:
2
,
"status"
:
"running"
,
"stage"
:
"test"
,
"name"
:
"test"
,
"ref"
:
"master"
,
"tag"
:
false
,
"coverage"
:
null
,
"created_at"
:
"2017-11-16T08:50:29.000Z"
,
"started_at"
:
"2017-11-16T08:51:29.000Z"
,
"finished_at"
:
"2017-11-16T08:53:29.000Z"
,
"duration"
:
120
,
"user"
:
null
,
"commit"
:
null
,
"runner"
:
{
"id"
:
1
,
"description"
:
"My runner1"
,
"active"
:
true
,
"is_shared"
:
true
,
"name"
:
null
},
"pipeline"
:
{
"id"
:
2
,
"sha"
:
"97de212e80737a608d939f648d959671fb0a0142"
,
"ref"
:
"master"
,
"status"
:
"pending"
}
}
]
```
## List project's runners
## List project's runners
List all runners (specific and shared) available in the project. Shared runners
List all runners (specific and shared) available in the project. Shared runners
...
...
lib/api/runners.rb
View file @
623eb681
...
@@ -84,6 +84,18 @@ module API
...
@@ -84,6 +84,18 @@ module API
destroy_conditionally!
(
runner
)
destroy_conditionally!
(
runner
)
end
end
desc
'List jobs running on a runner'
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
use
:pagination
end
get
':id/jobs'
do
runner
=
get_runner
(
params
[
:id
])
authenticate_list_runners_jobs!
(
runner
)
present
paginate
(
runner
.
builds
.
running
),
with:
Entities
::
Job
end
end
end
params
do
params
do
...
@@ -192,6 +204,12 @@ module API
...
@@ -192,6 +204,12 @@ module API
forbidden!
(
"No access granted"
)
unless
user_can_access_runner?
(
runner
)
forbidden!
(
"No access granted"
)
unless
user_can_access_runner?
(
runner
)
end
end
def
authenticate_list_runners_jobs!
(
runner
)
return
if
current_user
.
admin?
forbidden!
(
"No access granted"
)
unless
user_can_access_runner?
(
runner
)
end
def
user_can_access_runner?
(
runner
)
def
user_can_access_runner?
(
runner
)
current_user
.
ci_authorized_runners
.
exists?
(
runner
.
id
)
current_user
.
ci_authorized_runners
.
exists?
(
runner
.
id
)
end
end
...
...
spec/requests/api/runners_spec.rb
View file @
623eb681
...
@@ -354,6 +354,98 @@ describe API::Runners do
...
@@ -354,6 +354,98 @@ describe API::Runners do
end
end
end
end
describe
'GET /runners/:id/jobs'
do
let!
(
:job_1
)
{
create
(
:ci_build
)
}
let!
(
:job_2
)
{
create
(
:ci_build
,
:running
,
runner:
shared_runner
)
}
let!
(
:job_3
)
{
create
(
:ci_build
,
:failed
,
runner:
shared_runner
)
}
let!
(
:job_4
)
{
create
(
:ci_build
,
:running
,
runner:
specific_runner
)
}
let!
(
:job_5
)
{
create
(
:ci_build
,
:failed
,
runner:
specific_runner
)
}
context
'admin user'
do
context
'when runner exists'
do
context
'when runner is shared'
do
it
'return jobs'
do
get
api
(
"/runners/
#{
shared_runner
.
id
}
/jobs"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
[
0
]).
to
include
(
'id'
=>
job_2
.
id
)
end
end
context
'when runner is specific'
do
it
'return jobs'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs"
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
[
0
]).
to
include
(
'id'
=>
job_4
.
id
)
end
end
end
context
"when runner doesn't exist"
do
it
'returns 404'
do
get
api
(
'/runners/9999/jobs'
,
admin
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
"runner project's administrative user"
do
context
'when runner exists'
do
context
'when runner is shared'
do
it
'returns 403'
do
get
api
(
"/runners/
#{
shared_runner
.
id
}
/jobs"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'when runner is specific'
do
it
'return jobs'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
[
0
]).
to
include
(
'id'
=>
job_4
.
id
)
end
end
end
context
"when runner doesn't exist"
do
it
'returns 404'
do
get
api
(
'/runners/9999/jobs'
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'other authorized user'
do
it
'does not return jobs'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs"
,
user2
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not return jobs'
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
/jobs"
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
end
describe
'GET /projects/:id/runners'
do
describe
'GET /projects/:id/runners'
do
context
'authorized user with master privileges'
do
context
'authorized user with master privileges'
do
it
"returns project's runners"
do
it
"returns project's runners"
do
...
...
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