Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add WipeOut of Job #270

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
18 changes: 18 additions & 0 deletions jenkins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,21 @@ 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")
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")
}
11 changes: 11 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down