From 2d9e69b9cb0d2eadaee75948fb2e78b457197b5c Mon Sep 17 00:00:00 2001 From: hackerzgz Date: Tue, 22 Feb 2022 18:25:56 +0800 Subject: [PATCH 1/3] feat(job): add wipe out api for job support --- jenkins_test.go | 12 ++++++++++++ job.go | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/jenkins_test.go b/jenkins_test.go index 4f4f1af0..2fd35246 100644 --- a/jenkins_test.go +++ b/jenkins_test.go @@ -384,3 +384,15 @@ func getFileAsString(path string) string { return string(buf) } + +func TestWipeOutWorkspace(t *testing.T) { + if _, ok := os.LookupEnv(integration_test); !ok { + return + } + + ctx := context.Background() + job, _ := jenkins.GetJob(ctx, "Job1_test_wipeout") + succ, err := job.WipeOut(ctx) + assert.Nil(t, err, "Failed to call wipe out") + assert.Equal(t, true, succ, "Unexpected wipe out result") +} diff --git a/job.go b/job.go index 1936af79..29bf8d76 100644 --- a/job.go +++ b/job.go @@ -310,6 +310,17 @@ func (j *Job) Delete(ctx context.Context) (bool, error) { return true, nil } +func (j *Job) WipeOut(ctx context.Context) (bool, error) { + resp, err := j.Jenkins.Requester.Post(ctx, j.Base+"/doWipeOutWorkspace", nil, nil, nil) + if err != nil { + return false, err + } + if resp.StatusCode != 200 { + return false, errors.New(strconv.Itoa(resp.StatusCode)) + } + return true, nil +} + func (j *Job) Rename(ctx context.Context, name string) (bool, error) { data := url.Values{} data.Set("newName", name) From ffa3790cd509e89938b8ec019b9601232a1a92d4 Mon Sep 17 00:00:00 2001 From: hackerzgz Date: Tue, 22 Feb 2022 18:37:59 +0800 Subject: [PATCH 2/3] test: update wipe out job unit test --- jenkins_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jenkins_test.go b/jenkins_test.go index 2fd35246..74cbb776 100644 --- a/jenkins_test.go +++ b/jenkins_test.go @@ -391,8 +391,14 @@ func TestWipeOutWorkspace(t *testing.T) { } ctx := context.Background() - job, _ := jenkins.GetJob(ctx, "Job1_test_wipeout") + job, _ := jenkins.GetJob(ctx, "Job1_test") succ, err := job.WipeOut(ctx) assert.Nil(t, err, "Failed to call wipe out") assert.Equal(t, true, succ, "Unexpected wipe out result") + + // attempts to wipe out job in folder + job, _ = jenkins.GetJob(ctx, "folder1_test/job/Job_test") + succ, err = job.WipeOut(ctx) + assert.Nil(t, err, "Failed to call wipe out") + assert.Equal(t, true, succ, "Unexpected wipe out result") } From ea4ef73e54ccdfd0f683e590aec2676c3fd4759d Mon Sep 17 00:00:00 2001 From: hackerzgz Date: Wed, 23 Feb 2022 11:04:59 +0800 Subject: [PATCH 3/3] feat(jenkins): update wipe out job API entertament of Jenkins --- jenkins.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jenkins.go b/jenkins.go index 86dc7191..200f5540 100644 --- a/jenkins.go +++ b/jenkins.go @@ -264,6 +264,12 @@ func (j *Jenkins) DeleteJob(ctx context.Context, name string) (bool, error) { return job.Delete(ctx) } +// Wipe out workspace of a job. +func (j *Jenkins) WipeOutJob(ctx context.Context, name string) (bool, error) { + job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name} + return job.WipeOut(ctx) +} + // Get a job object func (j *Jenkins) GetJobObj(ctx context.Context, name string) *Job { return &Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name}