From fb1a458414ad597a362162de19b3dfd8f27d49fc Mon Sep 17 00:00:00 2001 From: alswl Date: Thu, 2 Dec 2021 21:47:02 +0800 Subject: [PATCH] feat: add InvokeSimpleWithRawParam for multi params with same key name Signed-off-by: alswl --- job.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/job.go b/job.go index 1936af79..81983e7f 100644 --- a/job.go +++ b/job.go @@ -419,7 +419,8 @@ func (j *Job) HasQueuedBuild() { panic("Not Implemented yet") } -func (j *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64, error) { +// InvokeSimpleWithRawParam starts a build with parameters in url.Values, it allowed duplicate key. +func (j *Job) InvokeSimpleWithRawParam(ctx context.Context, params url.Values) (int64, error) { isQueued, err := j.IsQueued(ctx) if err != nil { return 0, err @@ -437,11 +438,7 @@ func (j *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64 if len(parameters) > 0 { endpoint = "/buildWithParameters" } - data := url.Values{} - for k, v := range params { - data.Set(k, v) - } - resp, err := j.Jenkins.Requester.Post(ctx, j.Base+endpoint, bytes.NewBufferString(data.Encode()), nil, nil) + resp, err := j.Jenkins.Requester.Post(ctx, j.Base+endpoint, bytes.NewBufferString(params.Encode()), nil, nil) if err != nil { return 0, err } @@ -468,6 +465,15 @@ func (j *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64 return number, nil } +// InvokeSimple starts a build with parameters in map. +func (j *Job) InvokeSimple(ctx context.Context, params map[string]string) (int64, error) { + data := url.Values{} + for k, v := range params { + data.Set(k, v) + } + return j.InvokeSimpleWithRawParam(ctx, data) +} + func (j *Job) Invoke(ctx context.Context, files []string, skipIfRunning bool, params map[string]string, cause string, securityToken string) (bool, error) { isQueued, err := j.IsQueued(ctx) if err != nil {