Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jenkinsci
Jenkins Cli
提交
e49ca18f
J
Jenkins Cli
项目概览
jenkinsci
/
Jenkins Cli
通知
0
Star
1
Fork
0
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
e49ca18f
编写于
7月 23, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support print job histroy as the table format
上级
fdc708ea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
31 deletion
+79
-31
app/cmd/common.go
app/cmd/common.go
+4
-0
app/cmd/job.go
app/cmd/job.go
+2
-30
app/cmd/job_history.go
app/cmd/job_history.go
+72
-0
app/cmd/job_search.go
app/cmd/job_search.go
+1
-1
未找到文件。
app/cmd/common.go
浏览文件 @
e49ca18f
...
...
@@ -35,6 +35,10 @@ func (o *OutputOption) Output(obj interface{}) (data []byte, err error) {
return
nil
,
fmt
.
Errorf
(
"not support format %s"
,
o
.
Format
)
}
func
(
o
*
OutputOption
)
SetFlag
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringVarP
(
&
o
.
Format
,
"output"
,
"o"
,
"table"
,
"Format the output (default 'json')"
)
}
func
Format
(
obj
interface
{},
format
string
)
(
data
[]
byte
,
err
error
)
{
if
format
==
JsonOutputFormat
{
return
json
.
MarshalIndent
(
obj
,
""
,
" "
)
...
...
app/cmd/job.go
浏览文件 @
e49ca18f
package
cmd
import
(
"fmt"
"log"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
...
...
@@ -21,37 +17,13 @@ func init() {
rootCmd
.
AddCommand
(
jobCmd
)
jobCmd
.
PersistentFlags
()
.
StringVarP
(
&
jobOption
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
jobCmd
.
PersistentFlags
()
.
StringVarP
(
&
jobOption
.
Name
,
"name"
,
"n"
,
""
,
"Name of the job"
)
jobCmd
.
Flags
()
.
BoolVarP
(
&
jobOption
.
History
,
"history"
,
""
,
false
,
"Print the build history of job"
)
}
var
jobCmd
=
&
cobra
.
Command
{
Use
:
"job
-n
"
,
Use
:
"job"
,
Short
:
"Print the job of your Jenkins"
,
Long
:
`Print the job of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
jobOption
.
Name
==
""
{
cmd
.
Help
()
return
}
jenkins
:=
getCurrentJenkins
()
jclient
:=
&
client
.
JobClient
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
if
jobOption
.
History
{
if
builds
,
err
:=
jclient
.
GetHistory
(
jobOption
.
Name
);
err
==
nil
{
var
data
[]
byte
if
data
,
err
=
Format
(
builds
,
jobOption
.
Format
);
err
==
nil
{
fmt
.
Printf
(
"%s
\n
"
,
string
(
data
))
}
else
{
log
.
Fatal
(
err
)
}
}
else
{
log
.
Fatal
(
err
)
}
}
cmd
.
Help
()
},
}
app/cmd/job_history.go
0 → 100644
浏览文件 @
e49ca18f
package
cmd
import
(
"fmt"
"log"
"os"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/linuxsuren/jenkins-cli/util"
"github.com/spf13/cobra"
)
type
JobHistoryOption
struct
{
OutputOption
}
var
jobHistoryOption
JobHistoryOption
func
init
()
{
jobCmd
.
AddCommand
(
jobHistoryCmd
)
jobHistoryOption
.
SetFlag
(
jobHistoryCmd
)
}
var
jobHistoryCmd
=
&
cobra
.
Command
{
Use
:
"history <keyword>"
,
Short
:
"Print the history of job in your Jenkins"
,
Long
:
`Print the history of job in your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
args
)
==
0
{
cmd
.
Help
()
return
}
jobName
:=
args
[
0
]
jenkins
:=
getCurrentJenkins
()
jclient
:=
&
client
.
JobClient
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
if
builds
,
err
:=
jclient
.
GetHistory
(
jobName
);
err
==
nil
{
if
data
,
err
:=
jobHistoryOption
.
Output
(
builds
);
err
==
nil
{
if
len
(
data
)
>
0
{
fmt
.
Println
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
}
else
{
log
.
Fatal
(
err
)
}
},
}
func
(
o
*
JobHistoryOption
)
Output
(
obj
interface
{})
(
data
[]
byte
,
err
error
)
{
if
data
,
err
=
o
.
OutputOption
.
Output
(
obj
);
err
!=
nil
{
buildList
:=
obj
.
([]
client
.
JobBuild
)
table
:=
util
.
CreateTable
(
os
.
Stdout
)
table
.
AddRow
(
"number"
,
"displayname"
,
"building"
,
"result"
)
for
i
,
build
:=
range
buildList
{
table
.
AddRow
(
fmt
.
Sprintf
(
"%d"
,
i
),
build
.
DisplayName
,
fmt
.
Sprintf
(
"%v"
,
build
.
Building
),
build
.
Result
)
}
table
.
Render
()
err
=
nil
data
=
[]
byte
{}
}
return
}
app/cmd/job_search.go
浏览文件 @
e49ca18f
...
...
@@ -16,7 +16,7 @@ var jobSearchOption JobSearchOption
func
init
()
{
jobCmd
.
AddCommand
(
jobSearchCmd
)
jobSearchCmd
.
PersistentFlags
()
.
StringVarP
(
&
queue
Option
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
jobSearchCmd
.
Flags
()
.
StringVarP
(
&
jobSearch
Option
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
}
var
jobSearchCmd
=
&
cobra
.
Command
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录