forked from jenkins-zh/jenkins-cli
/
plugin_check.go
41 lines (36 loc) · 935 Bytes
/
plugin_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cmd
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
func init() {
pluginCmd.AddCommand(pluginCheckCmd)
}
var pluginCheckCmd = &cobra.Command{
Use: "check",
Short: "Checkout update center server",
Long: `Checkout update center server`,
Run: func(cmd *cobra.Command, args []string) {
jenkins := getCurrentJenkins()
jclient := &client.PluginManager{}
jclient.URL = jenkins.URL
jclient.UserName = jenkins.UserName
jclient.Token = jenkins.Token
jclient.Proxy = jenkins.Proxy
jclient.ProxyAuth = jenkins.ProxyAuth
jclient.CheckUpdate(func(response *http.Response) {
code := response.StatusCode
if code == 200 {
fmt.Println("update site updated.")
} else {
contentData, _ := ioutil.ReadAll(response.Body)
log.Fatal(fmt.Sprintf("response code is %d, content: %s",
code, string(contentData)))
}
})
},
}