Skip to content

Commit

Permalink
support to get label
Browse files Browse the repository at this point in the history
  • Loading branch information
supereagle committed Dec 1, 2016
1 parent abbd5c1 commit d23256e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ func (j *Jenkins) GetNode(name string) (*Node, error) {
return nil, errors.New("No node found")
}

func (j *Jenkins) GetLabel(name string) (*Label, error) {
label := Label{Jenkins: j, Raw: new(LabelResponse), Base: "/label/" + name}
status, err := label.Poll()
if err != nil {
return nil, err
}
if status == 200 {
return &label, nil
}
return nil, errors.New("No label found")
}

func (j *Jenkins) GetBuild(jobName string, number int64) (*Build, error) {
job, err := j.GetJob(jobName)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gojenkins

type Label struct {
Raw *LabelResponse
Jenkins *Jenkins
Base string
}

type MODE string

const (
NORMAL MODE = "NORMAL"
EXCLUSIVE = "EXCLUSIVE"
)

type LabelNode struct {
NodeName string `json:"nodeName"`
NodeDescription string `json:"nodeDescription"`
NumExecutors int64 `json:"numExecutors"`
Mode string `json:"mode"`
Class string `json:"_class"`
}

type LabelResponse struct {
Name string `json:"name"`
Description string `json:"description"`
Nodes []LabelNode `json:"nodes"`
Offline bool `json:"offline"`
IdleExecutors int64 `json:"idleExecutors"`
BusyExecutors int64 `json:"busyExecutors"`
TotalExecutors int64 `json:"totalExecutors"`
}

func (l *Label) Poll() (int, error) {
response, err := l.Jenkins.Requester.GetJSON(l.Base, l.Raw, nil)
if err != nil {
return 0, err
}
return response.StatusCode, nil
}

0 comments on commit d23256e

Please sign in to comment.