You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/cmd/cli/cmd/cancelbuild.go
+73-57
Original file line number
Diff line number
Diff line change
@@ -33,78 +33,94 @@ Examples:
33
33
// To cancel a build its name has to be specified, and two options
34
34
// are available: displaying logs and restarting.
35
35
funcNewCmdCancelBuild(fullNamestring, f*clientcmd.Factory, out io.Writer) *cobra.Command {
36
-
37
36
cmd:=&cobra.Command{
38
37
Use: "cancel-build <build>",
39
38
Short: "Cancel a pending or running build.",
40
39
Long: fmt.Sprintf(cancelBuildLongDesc, fullName),
41
40
Run: func(cmd*cobra.Command, args []string) {
41
+
err:=RunCancelBuild(f, out, cmd, args)
42
+
cmdutil.CheckErr(err)
43
+
},
44
+
}
42
45
43
-
iflen(args) ==0||len(args[0]) ==0 {
44
-
usageError(cmd, "You must specify the name of a build to cancel.")
45
-
}
46
+
cmd.Flags().Bool("dump-logs", false, "Specify if the build logs for the cancelled build should be shown.")
47
+
cmd.Flags().Bool("restart", false, "Specify if a new build should be created after the current build is cancelled.")
48
+
returncmd
49
+
}
46
50
47
-
buildName:=args[0]
48
-
namespace, err:=f.DefaultNamespace()
49
-
checkErr(err)
51
+
funcRunCancelBuild(f*clientcmd.Factory, out io.Writer, cmd*cobra.Command, args []string) error {
52
+
iflen(args) ==0||len(args[0]) ==0 {
53
+
returncmdutil.UsageError(cmd, "You must specify the name of a build to cancel.")
54
+
}
50
55
51
-
client, _, err:=f.Clients()
52
-
checkErr(err)
53
-
buildClient:=client.Builds(namespace)
54
-
build,err:=buildClient.Get(buildName)
55
-
checkErr(err)
56
+
buildName:=args[0]
57
+
namespace, err:=f.DefaultNamespace()
58
+
iferr!=nil {
59
+
returnerr
60
+
}
56
61
57
-
if!isBuildCancellable(build) {
58
-
return
59
-
}
62
+
client, _, err:=f.Clients()
63
+
iferr!=nil {
64
+
returnerr
65
+
}
66
+
buildClient:=client.Builds(namespace)
67
+
build, err:=buildClient.Get(buildName)
68
+
iferr!=nil {
69
+
returnerr
70
+
}
60
71
61
-
// Print build logs before cancelling build.
62
-
ifcmdutil.GetFlagBool(cmd, "dump-logs") {
63
-
// in order to dump logs, you must have a pod assigned to the build. Since build pod creation is asynchronous, it is possible to cancel a build without a pod being assigned.
64
-
ifbuild.Status!=buildapi.BuildStatusRunning {
65
-
glog.V(2).Infof("Build %v has not yet generated any logs.", buildName)
// in order to dump logs, you must have a pod assigned to the build. Since build pod creation is asynchronous, it is possible to cancel a build without a pod being assigned.
79
+
ifbuild.Status!=buildapi.BuildStatusRunning {
80
+
glog.V(2).Infof("Build %v has not yet generated any logs.", buildName)
0 commit comments