@@ -11,6 +11,7 @@ import (
1111 "log"
1212 "os"
1313 "strings"
14+ "time"
1415
1516 "github.com/elastic/trigger-jenkins-buildkite-plugin/jenkins"
1617)
@@ -44,6 +45,11 @@ func jenkinsJobOptions() []string {
4445
4546func main () {
4647 jenkinsJob := flag .String ("jenkins-job" , "" , fmt .Sprintf ("Jenkins job to trigger. Allowed values: %s" , strings .Join (jenkinsJobOptions (), " ," )))
48+ waitingTime := flag .Duration ("waiting-time" , 5 * time .Second , fmt .Sprintf ("Waiting period between each retry" ))
49+ growthFactor := flag .Float64 ("growth-factor" , 1.25 , fmt .Sprintf ("Growth-Factor used for exponential backoff delays" ))
50+ retries := flag .Int ("retries" , 20 , fmt .Sprintf ("Number of retries to trigger the job" ))
51+ maxWaitingTime := flag .Duration ("max-waiting-time" , 60 * time .Minute , fmt .Sprintf ("Maximum waiting time per each retry" ))
52+
4753 folderPath := flag .String ("folder" , "" , "Path to artifacts folder" )
4854 zipPackagePath := flag .String ("package" , "" , "Path to zip package file (*.zip)" )
4955 sigPackagePath := flag .String ("signature" , "" , "Path to the signature file of the package file (*.zip.sig)" )
@@ -62,11 +68,18 @@ func main() {
6268 log .Fatalf ("error creating jenkins client" )
6369 }
6470
71+ opts := jenkins.Options {
72+ WaitingTime : * waitingTime ,
73+ Retries : * retries ,
74+ GrowthFactor : * growthFactor ,
75+ MaxWaitingTime : * maxWaitingTime ,
76+ }
77+
6578 switch * jenkinsJob {
6679 case publishJobKey :
67- err = runPublishingRemoteJob (ctx , client , * async , allowedJenkinsJobs [* jenkinsJob ], * zipPackagePath , * sigPackagePath )
80+ err = runPublishingRemoteJob (ctx , client , * async , allowedJenkinsJobs [* jenkinsJob ], * zipPackagePath , * sigPackagePath , opts )
6881 case signJobKey :
69- err = runSignPackageJob (ctx , client , * async , allowedJenkinsJobs [* jenkinsJob ], * folderPath )
82+ err = runSignPackageJob (ctx , client , * async , allowedJenkinsJobs [* jenkinsJob ], * folderPath , opts )
7083 default :
7184 log .Fatal ("unsupported jenkins job" )
7285 }
@@ -76,18 +89,18 @@ func main() {
7689 }
7790}
7891
79- func runSignPackageJob (ctx context.Context , client * jenkins.JenkinsClient , async bool , jobName , folderPath string ) error {
92+ func runSignPackageJob (ctx context.Context , client * jenkins.JenkinsClient , async bool , jobName , folderPath string , opts jenkins. Options ) error {
8093 if folderPath == "" {
8194 return fmt .Errorf ("missing parameter --gcs_input_path for" )
8295 }
8396 params := map [string ]string {
8497 "gcs_input_path" : folderPath ,
8598 }
8699
87- return client .RunJob (ctx , jobName , async , params )
100+ return client .RunJob (ctx , jobName , async , params , opts )
88101}
89102
90- func runPublishingRemoteJob (ctx context.Context , client * jenkins.JenkinsClient , async bool , jobName , packagePath , signaturePath string ) error {
103+ func runPublishingRemoteJob (ctx context.Context , client * jenkins.JenkinsClient , async bool , jobName , packagePath , signaturePath string , opts jenkins. Options ) error {
91104 if packagePath == "" {
92105 return fmt .Errorf ("missing parameter --gs_package_build_zip_path" )
93106 }
@@ -102,5 +115,5 @@ func runPublishingRemoteJob(ctx context.Context, client *jenkins.JenkinsClient,
102115 "gs_package_signature_path" : signaturePath ,
103116 }
104117
105- return client .RunJob (ctx , jobName , async , params )
118+ return client .RunJob (ctx , jobName , async , params , opts )
106119}
0 commit comments