Skip to content

Instantly share code, notes, and snippets.

@titimoby
Created July 9, 2014 10:20
Show Gist options
  • Save titimoby/75be04baf56324927672 to your computer and use it in GitHub Desktop.
Save titimoby/75be04baf56324927672 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"encoding/json"
"log"
"io/ioutil"
"net/http"
)
// play with http://mholt.github.io/json-to-go/
// this helped a lot
type BuildInfo struct {
Id string `json:"id"`
Number int `json:"number"`
Result string `json:"result"`
Timestamp int64 `json:"timestamp"`
Culprits []struct {
AbsoluteUrl string `json:"absoluteUrl"`
FullName string `json:"fullName"`
} `json:"culprits"`
}
type BuildType struct {
Builds []BuildInfo `json:"builds"`
}
func main() {
var username string = "YOUR USER"
var passwd string = "YOUR PASSWORD"
client := &http.Client{}
req, err := http.NewRequest("GET", "http://YOUR_SERVER/job/YOUR_JOB/api/json?pretty=true&tree=builds[number,result,timestamp,id,jsonMap,culprits[fullName,absoluteUrl]]", nil)
req.SetBasicAuth(username, passwd)
resp, err := client.Do(req)
if err != nil{
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
var builds BuildType
json.Unmarshal(body, &builds)
fmt.Printf("builds : %v\n", builds)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment