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

Add inQueue field in Job struct #53

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Intellij
.idea
*.iml
26 changes: 21 additions & 5 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)

type Auth struct {
Expand Down Expand Up @@ -37,7 +38,10 @@ func (jenkins *Jenkins) SetHTTPClient(client *http.Client) {
}

func (jenkins *Jenkins) buildUrl(path string, params url.Values) (requestUrl string) {
requestUrl = jenkins.baseUrl + path + "/api/json"
if !strings.HasPrefix(path, jenkins.baseUrl) {
path = jenkins.baseUrl + path
}
requestUrl = path + "/api/json"
if params != nil {
queryString := params.Encode()
if queryString != "" {
Expand Down Expand Up @@ -222,13 +226,25 @@ func (jenkins *Jenkins) GetJobConfig(name string) (job MavenJobItem, err error)

// GetBuild returns a number-th build result of specified job.
func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/%d", job.Name, number), nil, &build)
err = jenkins.get(fmt.Sprintf("%s/%d", job.Url, number), nil, &build)
return
}

// GetBuildByJobName returns a number-th build result of specified job.
func (jenkins *Jenkins) GetBuildByJobId(jobId string, number int) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/%d", jobId, number), nil, &build)
return
}

// GetLastBuild returns the last build of specified job.
func (jenkins *Jenkins) GetLastBuild(job Job) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/lastBuild", job.Name), nil, &build)
err = jenkins.get(fmt.Sprintf("%s/lastBuild", job.Url), nil, &build)
return
}

// GetLastBuild returns the last build of specified job.
func (jenkins *Jenkins) GetLastBuildByJobId(jobId string) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/lastBuild", jobId), nil, &build)
return
}

Expand Down Expand Up @@ -265,9 +281,9 @@ func (jenkins *Jenkins) CreateView(listView ListView) error {
// Params can be nil.
func (jenkins *Jenkins) Build(job Job, params url.Values) error {
if hasParams(job) {
return jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil)
return jenkins.post(fmt.Sprintf("%s/buildWithParameters", job.Url), params, nil)
} else {
return jenkins.post(fmt.Sprintf("/job/%s/build", job.Name), params, nil)
return jenkins.post(fmt.Sprintf("%s/build", job.Url), params, nil)
}
}

Expand Down
39 changes: 33 additions & 6 deletions job.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gojenkins

import "encoding/xml"
import (
"encoding/xml"
)

type Artifact struct {
DisplayPath string `json:"displayPath"`
Expand All @@ -21,8 +23,9 @@ type ScmChangeSetPath struct {
type ChangeSetItem struct {
AffectedPaths []string `json:"affectedPaths"`
CommitId string `json:"commitId"`
Timestamp int `json:"timestamp"`
Timestamp int64 `json:"timestamp"`
Author ScmAuthor `json:"author"`
AuthorEmail string `json:"authorEmail"`
Comment string `json:"comment"`
Date string `json:"date"`
Id string `json:"id"`
Expand All @@ -40,12 +43,13 @@ type Build struct {
Number int `json:"number"`
Url string `json:"url"`

DisplayName string `json:"displayName"`
FullDisplayName string `json:"fullDisplayName"`
Description string `json:"description"`

Timestamp int `json:"timestamp"`
Duration int `json:"duration"`
EstimatedDuration int `json:"estimatedDuration"`
Timestamp int64 `json:"timestamp"`
Duration int64 `json:"duration"`
EstimatedDuration int64 `json:"estimatedDuration"`

Building bool `json:"building"`
KeepLog bool `json:"keepLog"`
Expand All @@ -54,7 +58,8 @@ type Build struct {
Artifacts []Artifact `json:"artifacts"`
Actions []Action `json:"actions"`

ChangeSet ScmChangeSet `json:"changeSet"`
ChangeSet ScmChangeSet `json:"changeSet"` // regular build
ChangeSets []ScmChangeSet `json:"changeSets"` // pipeline
}

type UpstreamCause struct {
Expand All @@ -64,13 +69,27 @@ type UpstreamCause struct {
UpstreamUrl string `json:"upstreamUrl"`
}

type QueueItem struct {
Id int `json:"id"`
Blocked bool `json:"blocked"`
Buildable bool `json:"buildable"`
InQueueSince int64 `json:"inQueueSince"`
Params string `json:"params"`
Stuck bool `json:"stuck"`
Url string `json:"url"`
Why string `json:"why"`
}

type Job struct {
Actions []Action `json:"actions"`
Name string `json:"name"`
Url string `json:"url"`
Color string `json:"color"`

Jobs []SubJobDescription `json:"jobs"`

Buildable bool `json:"buildable"`
InQueue bool `json:"inQueue"`
Builds []Build `json:"builds"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
Expand All @@ -83,9 +102,17 @@ type Job struct {
LastUnstableBuild Build `json:"lastUnstableBuild"`
LastUnsuccessfulBuild Build `json:"lastUnsuccessfulBuild"`

QueueItem QueueItem `json:"queueItem"`

Property []Property `json:"property"`
}

type SubJobDescription struct {
Name string `json:"name"`
Url string `json:"url"`
Color string `json:"color"`
}

type Health struct {
Description string `json:"description"`
}
Expand Down