wiki:BuildbotJson

buildbot_json.py tricks

WARNING: /json endpoint used by buildbot_json.py available only in Buildbot 0.8.*. Starting from Buildbot 0.9.0 /json endpoint was removed in favor of Data API.

Location

The file is located at https://github.com/buildbot/buildbot/blob/master/master/contrib/buildbot_json.py.

Connect to a buildbot master

Using buildbot's buildbot as an example:

./buildbot_json.py interactive build.chromium.org/p/chromium

Using chromium's buildbot as an example:

./buildbot_json.py interactive build.chromium.org/p/chromium

Print all the builders name

print '
'.join(b.builders.keys)

Generate a list of only a few builders

builders = [bu for bu in b.builders if 'XP' in bu.name]

Iterate over builds cached on the buildbot master memory (usually max a few hundreds)

for build in builder.builds:
  print build

Iterate over all builds, will thrash the server's memory!

for build in builder.builds.iterall():
  print build

Print the build steps

builder.builds[-1].steps.keys 

List failed tests for builds on some builders (note: replace builders by b.builders for all builders)

for builder in builders:
  print builder.name
  for build in builder.builds:
    if build.simplified_result is not False:
      continue
    print '%5d: %s' % (build.number, build.steps.failed)

List of failed test case for each failed test

def print_build(build):
  failed = ['%s: %s' % (step, [x[0] for x in build.steps[step].data['logs'][1:]]) for step in build.steps.failed]
  print '%-17s: %5d: %s' % (build.builder.name, build.number, failed)

for builder in builders:
  for build in builder.builds:
    if build.simplified_result is not False:
      continue
    print_build(build)

Get yesterday and twodaysago

import time
now = time.time()
yesterday = now - 24*60*60
twodaysago = yesterday - 24*60*60

print time.ctime(yesterday)
# Tue Mar 27 09:58:54 2012
print time.ctime(twodaysago)
# Mon Mar 26 09:58:54 2012

All builds between 2 dates

def get_builds_between(builder, start, end):
  out = []
  for build in builder.builds.iterall():
    if start <= build.start_time < end:
      out.insert(0, build)
    if start > build.start_time:
     break
  return out

builder = b.builders['XP Tests(1)']
builds = get_builds_between(builder, twodaysago, yesterday)
len(builds)
# 86
print 'Range: %s - %s' % (time.ctime(builds[0].start_time), time.ctime(builds[-1].start_time))
# Range: Mon Mar 26 10:21:39 2012 - Tue Mar 27 08:23:05 2012

builds = get_builds_between(builder, yesterday, now)

First and last build

min(b.number for b in builds)
max(b.number for b inbuilds)
time.ctime(builds[0].start_time)
time.ctime(builds[-1].start_time)
time.ctime(builds[0].end_time)
time.ctime(builds[-1].end_time)
# Average duration in seconds
sum(b.duration for b in builds if b.duration) / len(builds)

Histogram of test case failures for each builder

def gen_histogram_steps(builds):
  values = sum((build.steps.failed for build in builds), [])
  return dict((key, values.count(key)) for key in set(values))

for builder in builders:
  print builder.name
  print '
'.join('  %-23s: %3d' % (k, v) for k, v in gen_histogram_steps(builder.builds).iteritems())

Histogram of tests runs failed between Date1 and Date2

builds = get_builds_between(builder.builds, twodaysago, yesterday)
print '
'.join('  %-23s: %3d' % (k, v) for k, v in gen_histogram_steps(builds).iteritems())

Histogram of test case failures across builders

def gen_histogram_full(builders):
  out = {}
  for builder in builders:
    for build in builder.builds:
      for failed in build.steps.failed:
        out.setdefault(failed, 0)
        out[failed] += 1
  return out

print '
'.join('%-23s: %3d' % (k, v) for k, v in gen_histogram_full(builders).iteritems())

Histogram for a single step

def gen_histogram_step(builds, step):
  values = [build.steps[step].result for build in builds]
  return dict((key, values.count(key)) for key in set(values))

print '
'.join('%5s: %3d' % (k, v) for k, v in gen_histogram_step(builder.builds, 'browser_tests').iteritems())
# See buildbot_json.py's SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY
# for the values. None means the build isn't completed.

Commit queue job (for the chromium try server only)

builds = [build for build in builder.builds if build.blame[0] == 'commit-bot@chromium.org']

Commit queue failures (for the try server only)

def only_cq_failed(builder, step):
  cq_builds = [build for build in builder.builds if build.blame and build.blame[0] == 'commit-bot@chromium.org']
  cq_failed = [build.steps.failed for build in cq_builds if build.steps.failed]
  if cq_builds and cq_failed:
    print builder.name
    print '  Failures: %d out of %d' % (len(cq_failed), len(cq_builds))
    print '  Only %s failed: %d' % (step, len([1 for x in cq_failed if x == [step]]))

for builder in builders:
  only_cq_failed(builder, 'browser_tests')
Last modified 4 months ago Last modified on Jan 4, 2017, 12:01:22 AM