[Buildbot-devel] How to set build status in new style step?

Greg MacDonald gmacdonald at trionworlds.com
Thu Jun 25 21:39:18 UTC 2015


Hi Everyone,

I'm having problems with my new-style custom shell command in 0.8.12. If the process returns 1, the build step fails with the rest of the steps aborted as expected, yet the status is still green on the web page. The example in the documentation here: http://docs.buildbot.net/current/manual/new-style-steps.html refers to a convertResults method that doesn't exist. Please help, what am I missing?

Here's my code:

from buildbot.plugins import util
from re import compile, IGNORECASE
from buildbot.process import buildstep
from buildbot.status.results import FAILURE, EXCEPTION, WARNINGS
from twisted.internet import defer

class _LogObserver(util.LogLineObserver):
    prefix = 'Observed: '

    def __init__(self, warningPatterns=None, errorPatterns=None, failImmediately=True):
        self.step = None
        self.warningPatterns = [compile(i, IGNORECASE) for i in warningPatterns] if warningPatterns else []
        self.errorPatterns = [compile(i, IGNORECASE) for i in errorPatterns] if errorPatterns else []
        self.failImmediately = failImmediately
        util.LogLineObserver.__init__(self)
        self.warnings = []
        self.errors = []
        self._log = None

    @property
    def log(self):
        if not self._log:
            self._log = self.step.getLog('stdio')
        return self._log

    def _processLine(self, line):
        if line.startswith(self.prefix):
            return

        if any([i.search(line) for i in self.errorPatterns]):
            self.errors.append(line)
            self.log.addStderr(unicode(self.prefix + 'Error: ' + line))
            if self.failImmediately:
                self.log.addStderr(u'Aborting step.')
                raise buildstep.BuildStepFailed('Fatal error detected.')
        elif any([i.search(line) for i in self.warningPatterns]):
            self.warnings.append(line)
            self.log.addStderr(unicode(self.prefix + 'Warning: ' + line))

    def outLineReceived(self, line):
        self._processLine(line)

    def errLineReceived(self, line):
        self._processLine(line)

    def getResults(self):
        if len(self.errors) > 0:
            return FAILURE
        if len(self.warnings) > 0:
            return WARNINGS
        return None

class ObservedShellCommand(buildstep.ShellMixin, buildstep.BuildStep):
    """Detects errors and warnings in stdio of a shell command."""
    name = "observed_shell"

    def __init__(self, warningPatterns=None, errorPatterns=None, failImmediately=True, **kwargs):
        kwargs = self.setupShellMixin(kwargs)
        buildstep.BuildStep.__init__(self, **kwargs)

        self.logObserver = _LogObserver(warningPatterns, errorPatterns, failImmediately)
        self.addLogObserver('stdio', self.logObserver)

        self.stepResults = None

    def getCurrentSummary(self):
        if self.stepResults in [FAILURE, EXCEPTION]:
            return {'build': u'failed', 'step': u'failed'}
        return u'running'

    def getResultSummary(self):
        if self.stepResults in [FAILURE, EXCEPTION]:
            return {'build': u'failed', 'step': u'failed'}
        return {}

    @defer.inlineCallbacks
    def run(self):
        cmd = yield self.makeRemoteShellCommand()
        yield self.runCommand(cmd)
        if cmd.didFail():
            self.stepResults = cmd.results()
        else:
            observedResults = self.logObserver.getResults()
            self.stepResults = observedResults if observedResults else cmd.results()
        self._step_status.stepFinished(self.stepResults)
        self.updateSummary()
        defer.returnValue(self.stepResults)

And the config:

    factory.addStep(ObservedShellCommand(command=['foo.bat'],
                                       workdir=r'build\tools\thin',
                                       description=["Generate foo."],
                                       haltOnFailure=True,
                                       warningPatterns=["Error:"],
                                       ))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://buildbot.net/pipermail/devel/attachments/20150625/e285165b/attachment.html>


More information about the devel mailing list