Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jenkinsci
Jenkins Cli
提交
e7811b7d
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 搜索 >>
未验证
提交
e7811b7d
编写于
7月 11, 2020
作者:
JenkinsInChina
提交者:
GitHub
7月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add timeout option for plugin upload command (#428)
上级
2413e17e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
21 deletion
+27
-21
app/cmd/plugin_upload.go
app/cmd/plugin_upload.go
+21
-14
client/common.go
client/common.go
+1
-1
client/pluginManger.go
client/pluginManger.go
+5
-6
未找到文件。
app/cmd/plugin_upload.go
浏览文件 @
e7811b7d
...
...
@@ -3,7 +3,6 @@ package cmd
import
(
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/cmd/common"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"io/ioutil"
"log"
...
...
@@ -11,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/util"
...
...
@@ -25,6 +25,8 @@ type PluginUploadOption struct {
RemoteJenkins
string
ShowProgress
bool
FileName
string
// Timeout is the timeout when upload the plugin
Timeout
int64
RoundTripper
http
.
RoundTripper
...
...
@@ -37,24 +39,29 @@ var pluginUploadOption PluginUploadOption
func
init
()
{
pluginCmd
.
AddCommand
(
pluginUploadCmd
)
pluginUploadCmd
.
Flags
()
.
BoolVarP
(
&
pluginUploadOption
.
ShowProgress
,
"show-progress"
,
""
,
true
,
flags
:=
pluginUploadCmd
.
Flags
()
flags
.
BoolVarP
(
&
pluginUploadOption
.
ShowProgress
,
"show-progress"
,
""
,
true
,
i18n
.
T
(
"Whether show the upload progress"
))
pluginUploadCmd
.
Flags
()
.
StringVarP
(
&
pluginUploadOption
.
FileName
,
"file"
,
"f"
,
""
,
flags
.
StringVarP
(
&
pluginUploadOption
.
FileName
,
"file"
,
"f"
,
""
,
i18n
.
T
(
"The plugin file path which should end with .hpi"
))
pluginUploadCmd
.
Flags
()
.
StringVarP
(
&
pluginUploadOption
.
Remote
,
"remote"
,
"r"
,
""
,
flags
.
StringVarP
(
&
pluginUploadOption
.
Remote
,
"remote"
,
"r"
,
""
,
i18n
.
T
(
"Remote plugin URL"
))
pluginUploadCmd
.
Flags
()
.
StringVarP
(
&
pluginUploadOption
.
RemoteUser
,
"remote-user"
,
""
,
""
,
flags
.
StringVarP
(
&
pluginUploadOption
.
RemoteUser
,
"remote-user"
,
""
,
""
,
i18n
.
T
(
"User of remote plugin URL"
))
pluginUploadCmd
.
Flags
()
.
StringVarP
(
&
pluginUploadOption
.
RemotePassword
,
"remote-password"
,
""
,
""
,
flags
.
StringVarP
(
&
pluginUploadOption
.
RemotePassword
,
"remote-password"
,
""
,
""
,
i18n
.
T
(
"Password of remote plugin URL"
))
pluginUploadCmd
.
Flags
()
.
StringVarP
(
&
pluginUploadOption
.
RemoteJenkins
,
"remote-jenkins"
,
""
,
""
,
flags
.
StringVarP
(
&
pluginUploadOption
.
RemoteJenkins
,
"remote-jenkins"
,
""
,
""
,
i18n
.
T
(
"Remote Jenkins which will find from config list"
))
pluginUploadCmd
.
Flags
()
.
BoolVarP
(
&
pluginUploadOption
.
SkipPreHook
,
"skip-prehook"
,
""
,
false
,
flags
.
BoolVarP
(
&
pluginUploadOption
.
SkipPreHook
,
"skip-prehook"
,
""
,
false
,
i18n
.
T
(
"Whether skip the previous command hook"
))
pluginUploadCmd
.
Flags
()
.
BoolVarP
(
&
pluginUploadOption
.
SkipPostHook
,
"skip-posthook"
,
""
,
false
,
flags
.
BoolVarP
(
&
pluginUploadOption
.
SkipPostHook
,
"skip-posthook"
,
""
,
false
,
i18n
.
T
(
"Whether skip the post command hook"
))
flags
.
Int64VarP
(
&
pluginUploadOption
.
Timeout
,
"timeout"
,
""
,
120
,
"Timeout in second when upload the plugin"
)
if
err
:=
pluginUploadCmd
.
RegisterFlagCompletionFunc
(
"file"
,
pluginUploadOption
.
HPICompletion
);
err
!=
nil
{
pluginCmd
.
PrintErrln
(
err
)
}
...
...
@@ -135,22 +142,22 @@ jcli plugin upload sample.hpi --show-progress=false`,
executePostCmd
(
cmd
,
args
,
cmd
.
OutOrStdout
())
},
ValidArgsFunction
:
pluginUploadOption
.
HPICompletion
,
Run
:
func
(
cmd
*
cobra
.
Command
,
_
[]
string
)
{
Run
E
:
func
(
cmd
*
cobra
.
Command
,
_
[]
string
)
(
err
error
)
{
jclient
:=
&
client
.
PluginManager
{
JenkinsCore
:
client
.
JenkinsCore
{
RoundTripper
:
pluginUploadOption
.
RoundTripper
,
Output
:
cmd
.
OutOrStdout
(),
Timeout
:
time
.
Duration
(
pluginUploadOption
.
Timeout
)
*
time
.
Second
,
},
ShowProgress
:
pluginUploadOption
.
ShowProgress
,
}
getCurrentJenkinsAndClientOrDie
(
&
(
jclient
.
JenkinsCore
))
jclient
.
Debug
=
rootOptions
.
Debug
getCurrentJenkinsAndClient
(
&
(
jclient
.
JenkinsCore
))
if
pluginUploadOption
.
Remote
!=
""
{
defer
os
.
Remove
(
pluginUploadOption
.
pluginFilePath
)
}
err
:
=
jclient
.
Upload
(
pluginUploadOption
.
pluginFilePath
)
helper
.
CheckErr
(
cmd
,
err
)
err
=
jclient
.
Upload
(
pluginUploadOption
.
pluginFilePath
)
return
},
}
client/common.go
浏览文件 @
e7811b7d
...
...
@@ -64,7 +64,7 @@ func (j *JenkinsCore) GetClient() (client *http.Client) {
// make sure have a default timeout here
if
j
.
Timeout
<=
0
{
j
.
Timeout
=
5
j
.
Timeout
=
1
5
}
client
=
&
http
.
Client
{
...
...
client/pluginManger.go
浏览文件 @
e7811b7d
...
...
@@ -230,17 +230,16 @@ func (p *PluginManager) Upload(pluginFile string) (err error) {
return
}
p
.
AuthHandle
(
request
)
if
err
=
p
.
AuthHandle
(
request
);
err
!=
nil
{
return
}
client
:=
p
.
GetClient
()
jcli
:=
p
.
GetClient
()
var
response
*
http
.
Response
if
response
,
err
=
client
.
Do
(
request
);
err
!=
nil
{
if
response
,
err
=
jcli
.
Do
(
request
);
err
!=
nil
{
return
}
else
if
response
.
StatusCode
!=
200
{
err
=
fmt
.
Errorf
(
"StatusCode: %d"
,
response
.
StatusCode
)
if
data
,
readErr
:=
ioutil
.
ReadAll
(
response
.
Body
);
readErr
==
nil
&&
p
.
Debug
{
ioutil
.
WriteFile
(
debugLogFile
,
data
,
0664
)
}
}
return
err
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录