Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins-cli
提交
6855472a
J
jenkins-cli
项目概览
LinuxSuRen
/
jenkins-cli
与 Fork 源项目一致
Fork自
Jenkins 中文社区 / jenkins-cli
通知
1
Star
0
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 搜索 >>
提交
6855472a
编写于
6月 29, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
print the history of job
上级
5b013355
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
90 addition
and
1 deletion
+90
-1
app/cmd/job.go
app/cmd/job.go
+30
-1
client/job.go
client/job.go
+60
-0
未找到文件。
app/cmd/job.go
浏览文件 @
6855472a
package
cmd
import
(
"fmt"
"log"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type
JobOption
struct
{
OutputOption
Name
string
Name
string
History
bool
}
var
jobOption
JobOption
...
...
@@ -16,6 +21,7 @@ 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
.
PersistentFlags
()
.
BoolVarP
(
&
jobOption
.
History
,
"history"
,
""
,
false
,
"Print the build history of job"
)
}
var
jobCmd
=
&
cobra
.
Command
{
...
...
@@ -23,5 +29,28 @@ var jobCmd = &cobra.Command{
Short
:
"Print the job of your Jenkins"
,
Long
:
`Print the job of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
jobOption
.
Name
==
""
{
log
.
Fatal
(
"need a name"
)
}
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
)
}
}
},
}
client/job.go
浏览文件 @
6855472a
...
...
@@ -88,6 +88,51 @@ func (q *JobClient) Build(jobName string) (err error) {
return
}
func
(
q
*
JobClient
)
GetJob
(
name
string
)
(
job
*
Job
,
err
error
)
{
jobItems
:=
strings
.
Split
(
name
,
" "
)
path
:=
""
for
_
,
item
:=
range
jobItems
{
path
=
fmt
.
Sprintf
(
"%s/job/%s"
,
path
,
item
)
}
api
:=
fmt
.
Sprintf
(
"%s/%s/api/json"
,
q
.
URL
,
path
)
var
(
req
*
http
.
Request
response
*
http
.
Response
)
req
,
err
=
http
.
NewRequest
(
"GET"
,
api
,
nil
)
if
err
==
nil
{
q
.
AuthHandle
(
req
)
}
else
{
return
}
client
:=
q
.
GetClient
()
if
response
,
err
=
client
.
Do
(
req
);
err
==
nil
{
code
:=
response
.
StatusCode
var
data
[]
byte
data
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
code
==
200
{
job
=
&
Job
{}
err
=
json
.
Unmarshal
(
data
,
job
)
}
else
{
log
.
Fatal
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
return
}
func
(
q
*
JobClient
)
GetHistory
(
name
string
)
(
builds
[]
JobBuild
,
err
error
)
{
var
job
*
Job
if
job
,
err
=
q
.
GetJob
(
name
);
err
==
nil
{
builds
=
job
.
Builds
}
return
}
// Log get the log of a job
func
(
q
*
JobClient
)
Log
(
jobName
string
,
start
int64
)
(
jobLog
JobLog
,
err
error
)
{
jobItems
:=
strings
.
Split
(
jobName
,
" "
)
...
...
@@ -148,3 +193,18 @@ type SearchResult struct {
type
SearchResultItem
struct
{
Name
string
}
type
Job
struct
{
Builds
[]
JobBuild
Color
string
ConcurrentBuild
bool
Name
string
NextBuildNumber
int
URL
string
Buildable
bool
}
type
JobBuild
struct
{
Number
int
URL
string
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录