Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
623eb681
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
623eb681
编写于
11月 16, 2017
作者:
T
Tomasz Maczukin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add new API endpoint - list jobs of a specified runner
上级
8e7e2aeb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
161 addition
and
0 deletion
+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
未找到文件。
doc/api/runners.md
浏览文件 @
623eb681
...
...
@@ -215,6 +215,57 @@ DELETE /runners/:id
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 all runners (specific and shared) available in the project. Shared runners
...
...
lib/api/runners.rb
浏览文件 @
623eb681
...
...
@@ -84,6 +84,18 @@ module API
destroy_conditionally!
(
runner
)
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
params
do
...
...
@@ -192,6 +204,12 @@ module API
forbidden!
(
"No access granted"
)
unless
user_can_access_runner?
(
runner
)
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
)
current_user
.
ci_authorized_runners
.
exists?
(
runner
.
id
)
end
...
...
spec/requests/api/runners_spec.rb
浏览文件 @
623eb681
...
...
@@ -354,6 +354,98 @@ describe API::Runners do
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
context
'authorized user with master privileges'
do
it
"returns project's runners"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录