Skip to content

Commit

Permalink
Merge pull request #3125 from tardyp/build_status
Browse files Browse the repository at this point in the history
build status_string: store meaningful status at the end of the build
  • Loading branch information
tardyp committed Apr 26, 2017
2 parents fc1cc9b + fe41d15 commit 621dc55
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 149 deletions.
2 changes: 2 additions & 0 deletions master/buildbot/newsfragments/build_summary.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Builds ``state_string`` is now automatically computed according to the :py:meth:`BuildStep.getResultSummary`, :py:attr:`BuildStep.description` and ``updateBuildSummaryPolicy`` from :ref:`Buildstep-Common-Parameters`.
This allows the dashboards and reporters to get a descent summary text of the build without fetching the steps.
18 changes: 13 additions & 5 deletions master/buildbot/process/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from buildbot.process.results import worst_status
from buildbot.reporters.utils import getURLForBuild
from buildbot.util import bytes2NativeString
from buildbot.util import bytes2unicode
from buildbot.util.eventual import eventually
from buildbot.worker_transition import WorkerAPICompatMixin
from buildbot.worker_transition import deprecatedWorkerClassMethod
Expand Down Expand Up @@ -511,15 +512,17 @@ def _flushProperties(self, results):

defer.returnValue(results)

@defer.inlineCallbacks
def _stepDone(self, results, step):
self.currentStep = None
if self.finished:
return # build was interrupted, don't keep building
terminate = self.stepDone(results, step) # interpret/merge results
terminate = yield self.stepDone(results, step) # interpret/merge results
if terminate:
self.terminate = True
return self.startNextStep()
yield self.startNextStep()

@defer.inlineCallbacks
def stepDone(self, results, step):
"""This method is called when the BuildStep completes. It is passed a
status object from the BuildStep and is responsible for merging the
Expand All @@ -530,16 +533,21 @@ def stepDone(self, results, step):
if isinstance(results, tuple):
results, text = results
assert isinstance(results, type(SUCCESS)), "got %r" % (results,)
log.msg(" step '%s' complete: %s" % (step.name, statusToString(results)))
summary = yield step.getBuildResultSummary()
if 'build' in summary:
text = [summary['build']]
log.msg(" step '%s' complete: %s (%s)" % (step.name, statusToString(results), text))
if text:
self.text.extend(text)
self.master.data.updates.setBuildStateString(self.buildid,
bytes2unicode(" ".join(self.text)))
self.results, terminate = computeResultAndTermination(step, results,
self.results)
if not self.conn:
# force the results to retry if the connection was lost
self.results = RETRY
terminate = True
return terminate
defer.returnValue(terminate)

def lostRemote(self, conn=None):
# the worker went away. There are several possible reasons for this,
Expand Down Expand Up @@ -641,7 +649,7 @@ def buildFinished(self, text, results):
metrics.MetricCountEvent.log('active_builds', -1)

yield self.master.data.updates.setBuildStateString(self.buildid,
u'finished')
bytes2unicode(" ".join(text)))
yield self.master.data.updates.finishBuild(self.buildid, self.results)

# mark the build as finished
Expand Down
25 changes: 25 additions & 0 deletions master/buildbot/process/buildstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from buildbot.process import results
# (WithProperties used to be available in this module)
from buildbot.process.properties import WithProperties
from buildbot.process.results import ALL_RESULTS
from buildbot.process.results import CANCELLED
from buildbot.process.results import EXCEPTION
from buildbot.process.results import FAILURE
Expand Down Expand Up @@ -293,6 +294,7 @@ class BuildStep(results.ResultComputingConfigMixin,
'flunkOnFailure',
'flunkOnWarnings',
'haltOnFailure',
'updateBuildSummaryPolicy',
'hideStepIf',
'locks',
'logEncoding',
Expand All @@ -308,6 +310,7 @@ class BuildStep(results.ResultComputingConfigMixin,
description = None # set this to a list of short strings to override
descriptionDone = None # alternate description when the step is complete
descriptionSuffix = None # extra information to append to suffix
updateBuildSummaryPolicy = None
locks = []
progressMetrics = () # 'time' is implicit
useProgress = True # set to False if step is really unpredictable
Expand Down Expand Up @@ -346,6 +349,21 @@ def __init__(self, **kwargs):
if isinstance(self.descriptionSuffix, str):
self.descriptionSuffix = [self.descriptionSuffix]

if self.updateBuildSummaryPolicy is None: # compute default value for updateBuildSummaryPolicy
self.updateBuildSummaryPolicy = [EXCEPTION, RETRY, CANCELLED]
if self.flunkOnFailure or self.haltOnFailure or self.warnOnFailure:
self.updateBuildSummaryPolicy.append(FAILURE)
if self.warnOnWarnings or self.flunkOnWarnings:
self.updateBuildSummaryPolicy.append(WARNINGS)
self.updateBuildSummaryPolicy
if self.updateBuildSummaryPolicy is False:
self.updateBuildSummaryPolicy = []
if self.updateBuildSummaryPolicy is True:
self.updateBuildSummaryPolicy = ALL_RESULTS
if not isinstance(self.updateBuildSummaryPolicy, list):
config.error("BuildStep updateBuildSummaryPolicy must be "
"a list of result ids or boolean but it is %r" %
(self.updateBuildSummaryPolicy,))
self._acquiringLock = None
self.stopped = False
self.master = None
Expand Down Expand Up @@ -445,6 +463,13 @@ def getResultSummary(self):

return {u'step': stepsumm}

@defer.inlineCallbacks
def getBuildResultSummary(self):
summary = yield self.getResultSummary()
if self.results in self.updateBuildSummaryPolicy and u'build' not in summary and u'step' in summary:
summary[u'build'] = summary[u'step']
defer.returnValue(summary)

@debounce.method(wait=1)
@defer.inlineCallbacks
def updateSummary(self):
Expand Down
3 changes: 2 additions & 1 deletion master/buildbot/process/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from __future__ import print_function
from future.utils import lrange

SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY, CANCELLED = lrange(7)
ALL_RESULTS = lrange(7)
SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY, CANCELLED = ALL_RESULTS
Results = ["success", "warnings", "failure", "skipped", "exception", "retry", "cancelled"]


Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/integration/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
# with two builders and a trigger step linking them

expectedOutputRegex = \
r"""\*\*\* BUILD 1 \*\*\* ==> finished \(success\)
r"""\*\*\* BUILD 1 \*\*\* ==> build successful \(success\)
\*\*\* STEP shell \*\*\* ==> 'echo hello' \(success\)
log:stdio \({loglines}\)
\*\*\* STEP trigger \*\*\* ==> triggered trigsched \(success\)
url:trigsched #2 \(http://localhost:8080/#buildrequests/2\)
url:success: build #1 \(http://localhost:8080/#builders/(1|2)/builds/1\)
\*\*\* STEP shell_1 \*\*\* ==> 'echo world' \(success\)
log:stdio \({loglines}\)
\*\*\* BUILD 2 \*\*\* ==> finished \(success\)
\*\*\* BUILD 2 \*\*\* ==> build successful \(success\)
\*\*\* STEP shell \*\*\* ==> 'echo ola' \(success\)
log:stdio \({loglines}\)
"""
Expand Down
4 changes: 1 addition & 3 deletions master/buildbot/test/integration/test_try_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ def test_userpass_wait(self):
'Delivering job; comment= None',
'job has been delivered',
'All Builds Complete',
# XXX should be something like "build successful one two", but
# currently just drawn from the build status strings
'a: success (finished)',
'a: success (build successful)',
])
buildsets = yield self.master.db.buildsets.getBuildsets()
self.assertEqual(len(buildsets), 1)
Expand Down
Loading

0 comments on commit 621dc55

Please sign in to comment.