func main() { j, err := jenkins.NewFromConfig() if err != nil { fmt.Println("Could not configure jenkins: " + err.Error()) return } builds, err := j.Builds() if err != nil { fmt.Println(err.Error()) return } for _, value := range builds { fmt.Println(value.String()) } }
func main() { j, err := jenkins.NewFromConfig() if err != nil { fmt.Println("Could not configure jenkins: " + err.Error()) return } p := flag.String("pattern", "", "Pattern to restrict which jobs to report") l := flag.Bool("list", false, "List key names for job") la := flag.Bool("listall", false, "List key names for all jobs, not just the first that matches") flag.Parse() if (len(flag.Args()) != 0 && *l) || (len(flag.Args()) == 0 && !*l) { fmt.Println("Either specify fields to list or use -list to show field names") return } var pattern *regexp.Regexp if *p != "" { pattern = regexp.MustCompile(".*" + *p + ".*") } jobs, err := j.Jobs() if err != nil { fmt.Println("Could not list jobs " + err.Error()) return } for _, job := range jobs { if *p != "" && !pattern.MatchString(job.Name) { continue } cfg, err := j.JobInfo(job.Name) if err != nil { fmt.Printf("Could not fetch job %s due to %s", job, err.Error()) continue } if *l { for name, _ := range cfg { fmt.Printf("%s\t%s\n", job.Name, name) } if !*la { return } } else { for _, name := range flag.Args() { fmt.Printf("%s\t%s\t%s\n", job.Name, name, cfg[name]) } } } }
func main() { j, err := jenkins.NewFromConfig() if err != nil { fmt.Println("Could not configure jenkins: " + err.Error()) return } flag.Parse() builds, err := j.Builds() if err != nil { fmt.Println("Could not fetch nodes: " + err.Error()) return } for _, build := range builds { if nameMatch(build.Node, flag.Args()) || nameMatch(build.Build, flag.Args()) { info, err := j.NodeInfo(build.Node) if err != nil { fmt.Println("Could not get info about " + build.Node + ": " + err.Error()) } else { fmt.Printf("%s node %s building %s\n", info.Ip, build.Node, build.Build) } } } }