Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Jenkins 中文社区
jenkins-cli
提交
9266de06
J
jenkins-cli
项目概览
Jenkins 中文社区
/
jenkins-cli
通知
49
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins-cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9266de06
编写于
2月 16, 2020
作者:
LinuxSuRen
提交者:
GitHub
2月 16, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #327 from LinuxSuRen/job-search-by-parent
Support search job by parent name
上级
c0a0d8af
e52aabc2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
13 deletion
+34
-13
app/cmd/job_search.go
app/cmd/job_search.go
+10
-7
client/doc/README-zh.md
client/doc/README-zh.md
+9
-1
client/doc/README.md
client/doc/README.md
+9
-1
client/job.go
client/job.go
+4
-2
client/job_test_common.go
client/job_test_common.go
+2
-2
未找到文件。
app/cmd/job_search.go
浏览文件 @
9266de06
...
...
@@ -6,18 +6,18 @@ import (
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
"net/http"
)
// JobSearchOption is the options of job search command
type
JobSearchOption
struct
{
CommonOption
OutputOption
Name
string
Type
string
Parent
string
Start
int
Limit
int
Name
string
Type
string
RoundTripper
http
.
RoundTripper
}
var
jobSearchOption
JobSearchOption
...
...
@@ -29,9 +29,11 @@ func init() {
jobSearchCmd
.
Flags
()
.
IntVarP
(
&
jobSearchOption
.
Limit
,
"limit"
,
""
,
50
,
i18n
.
T
(
"The list of items limit"
))
jobSearchCmd
.
Flags
()
.
StringVarP
(
&
jobSearchOption
.
Name
,
"name"
,
""
,
""
,
i18n
.
T
(
"The name of
plugin
for search"
))
i18n
.
T
(
"The name of
items
for search"
))
jobSearchCmd
.
Flags
()
.
StringVarP
(
&
jobSearchOption
.
Type
,
"type"
,
""
,
""
,
i18n
.
T
(
"The type of plugin for search"
))
i18n
.
T
(
"The type of items for search"
))
jobSearchCmd
.
Flags
()
.
StringVarP
(
&
jobSearchOption
.
Parent
,
"parent"
,
""
,
""
,
i18n
.
T
(
"The parent of items for search"
))
jobSearchOption
.
SetFlagWithHeaders
(
jobSearchCmd
,
"Name,DisplayName,Type,URL"
)
healthCheckRegister
.
Register
(
getCmdPath
(
jobSearchCmd
),
&
jobSearchOption
)
...
...
@@ -52,6 +54,7 @@ var jobSearchCmd = &cobra.Command{
JenkinsCore
:
client
.
JenkinsCore
{
RoundTripper
:
jobSearchOption
.
RoundTripper
,
},
Parent
:
jobSearchOption
.
Parent
,
}
getCurrentJenkinsAndClient
(
&
(
jClient
.
JenkinsCore
))
...
...
client/doc/README-zh.md
浏览文件 @
9266de06
...
...
@@ -124,4 +124,12 @@ func BuildJob(jobBuild JobBuildOptions) (e error) {
e = jobClient.BuildWithParams(jobBuild.JobName, params)
return
}
```
\ No newline at end of file
```
## 插件依赖
本 Jenkins 客户端的部分 API 需要依赖特定的插件,请参考下面的列表:
| API | Plugin |
|---|---|
| Search Job |
[
pipeline-restful-api
](
https://github.com/jenkinsci/pipeline-restful-api-plugin
)
|
client/doc/README.md
浏览文件 @
9266de06
...
...
@@ -124,4 +124,12 @@ func BuildJob(jobBuild JobBuildOptions) (e error) {
e = jobClient.BuildWithParams(jobBuild.JobName, params)
return
}
```
\ No newline at end of file
```
## Plugin Dependencies
Pay attention to the part of the Jenkins CLI, they need some special plugins. Please read through the following table:
| API | Plugin |
|---|---|
| Search Job |
[
pipeline-restful-api
](
https://github.com/jenkinsci/pipeline-restful-api-plugin
)
|
client/job.go
浏览文件 @
9266de06
...
...
@@ -15,12 +15,14 @@ import (
// JobClient is client for operate jobs
type
JobClient
struct
{
JenkinsCore
Parent
string
}
// Search find a set of jobs by name
func
(
q
*
JobClient
)
Search
(
name
,
kind
string
,
start
,
limit
int
)
(
items
[]
JenkinsItem
,
err
error
)
{
err
=
q
.
RequestWithData
(
"GET"
,
fmt
.
Sprintf
(
"/items/list?name=%s&type=%s&start=%d&limit=%d"
,
name
,
kind
,
start
,
limit
),
err
=
q
.
RequestWithData
(
"GET"
,
fmt
.
Sprintf
(
"/items/list?name=%s&type=%s&start=%d&limit=%d
&parent=%s
"
,
name
,
kind
,
start
,
limit
,
q
.
Parent
),
nil
,
nil
,
200
,
&
items
)
return
}
...
...
client/job_test_common.go
浏览文件 @
9266de06
...
...
@@ -188,7 +188,7 @@ func PrepareForJobLog(roundTripper *mhttp.MockRoundTripper, rootURL, jobName str
// PrepareOneItem only for test
func
PrepareOneItem
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
,
name
,
kind
,
user
,
token
string
)
{
request
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s/items/list?name=%s&type=%s&start=%d&limit=%d"
,
request
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s/items/list?name=%s&type=%s&start=%d&limit=%d
&parent=
"
,
rootURL
,
name
,
kind
,
0
,
50
),
nil
)
response
:=
&
http
.
Response
{
StatusCode
:
200
,
...
...
@@ -204,7 +204,7 @@ func PrepareOneItem(roundTripper *mhttp.MockRoundTripper, rootURL, name, kind, u
// PrepareEmptyItems only for test
func
PrepareEmptyItems
(
roundTripper
*
mhttp
.
MockRoundTripper
,
rootURL
,
name
,
kind
,
user
,
token
string
)
{
request
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s/items/list?name=%s&type=%s&start=%d&limit=%d"
,
request
,
_
:=
http
.
NewRequest
(
"GET"
,
fmt
.
Sprintf
(
"%s/items/list?name=%s&type=%s&start=%d&limit=%d
&parent=
"
,
rootURL
,
name
,
kind
,
0
,
50
),
nil
)
response
:=
&
http
.
Response
{
StatusCode
:
200
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录