提交 e52aabc2 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Support search job by parent name

上级 c0a0d8af
......@@ -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))
......
......@@ -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) |
......@@ -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) |
......@@ -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
}
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册