@@ -15,11 +15,17 @@ import (
15
15
type JobBuildOption struct {
16
16
common.BatchOption
17
17
common.CommonOption
18
+ common.OutputOption
18
19
19
20
Param string
20
21
ParamArray []string
21
22
22
23
ParamFilePathArray []string
24
+
25
+ Wait bool
26
+ WaitTime int
27
+ Delay int
28
+ Cause string
23
29
}
24
30
25
31
var jobBuildOption JobBuildOption
@@ -31,14 +37,23 @@ func ResetJobBuildOption() {
31
37
32
38
func init () {
33
39
jobCmd .AddCommand (jobBuildCmd )
34
- jobBuildOption . SetFlag ( jobBuildCmd )
40
+ jobBuildCmd . Flags (). BoolVarP ( & jobBuildOption . Batch , "batch" , "b" , false , "Batch mode, no need confirm" )
35
41
jobBuildCmd .Flags ().StringVarP (& jobBuildOption .Param , "param" , "" , "" ,
36
42
i18n .T ("Parameters of the job which is JSON format" ))
37
43
jobBuildCmd .Flags ().StringArrayVar (& jobBuildOption .ParamArray , "param-entry" , nil ,
38
44
i18n .T ("Parameters of the job which are the entry format, for example: --param-entry name=value" ))
39
45
jobBuildCmd .Flags ().StringArrayVar (& jobBuildOption .ParamFilePathArray , "param-file" , nil ,
40
46
i18n .T ("Parameters of the job which is file path, for example: --param-file name=filename" ))
41
-
47
+ jobBuildCmd .Flags ().BoolVarP (& jobBuildOption .Wait , "wait" , "" , false ,
48
+ i18n .T ("If you want to wait for the build ID from Jenkins. You need to install plugin pipeline-restful-api first" ))
49
+ jobBuildCmd .Flags ().IntVarP (& jobBuildOption .WaitTime , "wait-timeout" , "" , 30 ,
50
+ i18n .T ("The timeout of seconds when you wait for the build ID" ))
51
+ jobBuildCmd .Flags ().IntVarP (& jobBuildOption .Delay , "delay" , "" , 0 ,
52
+ i18n .T ("Delay when trigger a Jenkins job" ))
53
+ jobBuildCmd .Flags ().StringVarP (& jobBuildOption .Cause , "cause" , "" , "triggered by jcli" ,
54
+ i18n .T ("The cause of a job build" ))
55
+
56
+ jobBuildOption .SetFlagWithHeaders (jobBuildCmd , "Number,URL" )
42
57
jobBuildOption .BatchOption .Stdio = common .GetSystemStdio ()
43
58
jobBuildOption .CommonOption .Stdio = common .GetSystemStdio ()
44
59
}
@@ -87,7 +102,7 @@ You need to give the parameters if your pipeline has them. Learn more about it f
87
102
}
88
103
return
89
104
},
90
- RunE : func (_ * cobra.Command , args []string ) (err error ) {
105
+ RunE : func (cmd * cobra.Command , args []string ) (err error ) {
91
106
name := args [0 ]
92
107
93
108
if ! jobBuildOption .Confirm (fmt .Sprintf ("Are you sure to build job %s" , name )) {
@@ -136,6 +151,12 @@ You need to give the parameters if your pipeline has them. Learn more about it f
136
151
if err == nil {
137
152
if hasParam {
138
153
err = jclient .BuildWithParams (name , paramDefs )
154
+ } else if jobBuildOption .Wait {
155
+ var build client.IdentityBuild
156
+ if build , err = jclient .BuildAndReturn (name , jobBuildOption .Cause , jobBuildOption .WaitTime , jobBuildOption .Delay ); err == nil {
157
+ jobBuildOption .Writer = cmd .OutOrStdout ()
158
+ err = jobBuildOption .OutputV2 ([1 ]client.SimpleJobBuild {build .Build .SimpleJobBuild })
159
+ }
139
160
} else {
140
161
err = jclient .Build (name )
141
162
}
0 commit comments