-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
job_delete.go
52 lines (42 loc) · 996 Bytes
/
job_delete.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
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"fmt"
"log"
"net/http"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
// JobDeleteOption is the job delete option
type JobDeleteOption struct {
BatchOption
RoundTripper http.RoundTripper
}
var jobDeleteOption JobDeleteOption
func init() {
jobCmd.AddCommand(jobDeleteCmd)
jobDeleteOption.SetFlag(jobDeleteCmd)
}
var jobDeleteCmd = &cobra.Command{
Use: "delete <jobName>",
Short: "Delete a job in your Jenkins",
Long: `Delete a job in your Jenkins`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
return
}
jobName := args[0]
if !jobDeleteOption.Confirm(fmt.Sprintf("Are you sure to delete job %s ?", jobName)) {
return
}
jclient := &client.JobClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: jobDeleteOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
if err := jclient.Delete(jobName); err != nil {
log.Fatal(err)
}
},
}