Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins-cli
提交
5b013355
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 搜索 >>
提交
5b013355
编写于
6月 29, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add sub-cmd to trigger a job
上级
62ed7a6e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
5 deletion
+79
-5
app/cmd/job.go
app/cmd/job.go
+4
-1
app/cmd/job_build.go
app/cmd/job_build.go
+33
-0
app/cmd/job_log.go
app/cmd/job_log.go
+2
-4
client/job.go
client/job.go
+40
-0
未找到文件。
app/cmd/job.go
浏览文件 @
5b013355
...
...
@@ -6,13 +6,16 @@ import (
type
JobOption
struct
{
OutputOption
Name
string
}
var
jobOption
JobOption
func
init
()
{
rootCmd
.
AddCommand
(
jobCmd
)
jobCmd
.
PersistentFlags
()
.
StringVarP
(
&
queueOption
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
jobCmd
.
PersistentFlags
()
.
StringVarP
(
&
jobOption
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
jobCmd
.
PersistentFlags
()
.
StringVarP
(
&
jobOption
.
Name
,
"name"
,
"n"
,
""
,
"Name of the job"
)
}
var
jobCmd
=
&
cobra
.
Command
{
...
...
app/cmd/job_build.go
0 → 100644
浏览文件 @
5b013355
package
cmd
import
(
"log"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
func
init
()
{
jobCmd
.
AddCommand
(
jobBuildCmd
)
}
var
jobBuildCmd
=
&
cobra
.
Command
{
Use
:
"build"
,
Short
:
"Build the job of your Jenkins"
,
Long
:
`Build 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
jclient
.
Build
(
jobOption
.
Name
)
},
}
app/cmd/job_log.go
浏览文件 @
5b013355
...
...
@@ -9,14 +9,12 @@ import (
)
type
JobLogOption
struct
{
Name
string
}
var
jobLogOption
JobLogOption
func
init
()
{
jobCmd
.
AddCommand
(
jobLogCmd
)
jobLogCmd
.
PersistentFlags
()
.
StringVarP
(
&
jobLogOption
.
Name
,
"name"
,
"n"
,
""
,
"Name of the job"
)
}
var
jobLogCmd
=
&
cobra
.
Command
{
...
...
@@ -24,7 +22,7 @@ var jobLogCmd = &cobra.Command{
Short
:
"Print the job of your Jenkins"
,
Long
:
`Print the job of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
job
Log
Option
.
Name
==
""
{
if
jobOption
.
Name
==
""
{
log
.
Fatal
(
"need a name"
)
}
...
...
@@ -36,7 +34,7 @@ var jobLogCmd = &cobra.Command{
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
printLog
(
jclient
,
job
Log
Option
.
Name
,
0
)
printLog
(
jclient
,
jobOption
.
Name
,
0
)
},
}
...
...
client/job.go
浏览文件 @
5b013355
...
...
@@ -48,6 +48,46 @@ func (q *JobClient) Search(keyword string) (status *SearchResult, err error) {
return
}
func
(
q
*
JobClient
)
Build
(
jobName
string
)
(
err
error
)
{
jobItems
:=
strings
.
Split
(
jobName
,
" "
)
path
:=
""
for
_
,
item
:=
range
jobItems
{
path
=
fmt
.
Sprintf
(
"%s/job/%s"
,
path
,
item
)
}
api
:=
fmt
.
Sprintf
(
"%s/%s/build"
,
q
.
URL
,
path
)
var
(
req
*
http
.
Request
response
*
http
.
Response
)
req
,
err
=
http
.
NewRequest
(
"POST"
,
api
,
nil
)
if
err
==
nil
{
q
.
AuthHandle
(
req
)
}
else
{
return
}
if
err
=
q
.
CrumbHandle
(
req
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
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
{
fmt
.
Println
(
"build successfully"
)
}
else
{
log
.
Fatal
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
return
}
// Log get the log of a job
func
(
q
*
JobClient
)
Log
(
jobName
string
,
start
int64
)
(
jobLog
JobLog
,
err
error
)
{
jobItems
:=
strings
.
Split
(
jobName
,
" "
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录