BuildBot:无法在master.cfg中注入扩展事件处理程序

时间:2018-07-16 11:59:04

标签: continuous-integration bitbucket buildbot

Buildbot版本:1.3.0
扭曲版本:18.4.0

  

我的master.cfg

# -*- python -*-
# ex: set filetype=python:

from buildbot.plugins import *
from config import *
import os
from hooks import CustomHandler

# ip related imports
import socket
import fcntl
import struct

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', bytes(ifname[:15], 'utf-8'))
    )[20:24])
#--------------------------------------------------------------
# CONSTANTS
localhost = get_ip_address(NETWORK_INTERFACE)
HOME = os.environ['HOME']

#--------------------------------------------------------------

c = BuildmasterConfig = {}



####### WORKERS

c['workers'] = [worker.Worker("example-worker", "pass")]


c['protocols'] = {'pb': {'port': 9989}}

c['www'] = dict(port=8010,plugins=dict(waterfall_view={}, console_view={}, grid_view={}))


####### CHANGESOURCES

c['www']['change_hook_dialects'] = { }
c['www']['change_hook_dialects']['bitbucketcloud'] = {
        'class': CustomHandler
        }


####### SCHEDULERS

c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="schedulerQueryBuilder",
                            change_filter=util.ChangeFilter(repository_re='.*/querybuilder',
                                                            branch_re='.*/build_bot_testing',
                                                            category='push'),
                            treeStableTimer=None,
                            builderNames=["BuilderOfQueryBuilder"]
                            ))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="build",
                            builderNames=["BuilderOfQueryBuilder"]))

####### BUILDERS

BitBucketFactory = util.BuildFactory()
BitBucketFactory.addStep(steps.Git(
                                    repourl='git@host:A/B.git',
                                    branch='build_bot_testing',
                                    retryFetch=True,
                                    clobberOnFailure=True,
                                    mode='incremental'))    

BitBucketFactory.addStep(steps.PyLint(command=['pylint', '--py3k', '--ignore ln2sql',
                                                '--disable C,import-error,import-error,too-few-public-methods,undefined-variable',
                                                'swagger_server'],
                                    haltOnFailure=True))                                  
BitBucketFactory.addStep(steps.Test(command=["pytest", "swagger_server"],
                                    haltOnFailure=False))
BitBucketFactory.addStep(steps.ShellSequence(commands=[
                                                util.ShellArg(command=['zip', '-r', '/home/rajat/buildbot/worker/BuilderOfQueryBuilder/build.zip',
                                                '/home/rajat/buildbot/worker/BuilderOfQueryBuilder/build'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),

                                                util.ShellArg(command=['scp', '-i', '/home/rajat/.ssh/id_rsa.pub', '-rp',
                                                '/home/rajat/buildbot/worker/BuilderOfQueryBuilder/build.zip',
                                                'rajat@192.168.0.21:/home/rajat/buildbot/querybuilder/build.zip'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),

                                                util.ShellArg(command=['ssh', '-i', '/home/rajat/.ssh/id_rsa.pub', 'rajat@192.168.0.21',
                                                'rm','-rf', '/home/rajat/buildbot/querybuilder/build'],
                                                            logfile='ShellSequenceLog', flunkOnFailure=True),

                                                util.ShellArg(command=['ssh', '-i', '/home/rajat/.ssh/id_rsa.pub', 'rajat@192.168.0.21',
                                                'unzip','-o', '/home/rajat/buildbot/querybuilder/build.zip', '-d', '/home/rajat/buildbot/querybuilder/'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),


                                                util.ShellArg(command=['ssh', '-i', '/home/rajat/.ssh/id_rsa.pub', 'rajat@192.168.0.21', 
                                                '/home/rajat/anaconda3/envs/querybuilder/bin/pip',
                                                'install', '--upgrade', 'setuptools'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),

                                                util.ShellArg(command=['ssh', '-i', '/home/rajat/.ssh/id_rsa.pub', 'rajat@192.168.0.21',
                                                '/home/rajat/anaconda3/envs/querybuilder/bin/pip', 'install', '-r', '/home/rajat/buildbot/querybuilder/build/requirements.txt'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),                            

                                                util.ShellArg(command=['ssh', '-f', '-i', '/home/rajat/.ssh/id_rsa.pub', 'rajat@192.168.0.21',
                                                'cd', '/home/rajat/buildbot/querybuilder/build','&&','nohup','/home/rajat/anaconda3/envs/querybuilder/bin/python', '-m',
                                                'swagger_server', '&>',
                                                '/home/rajat/logs/log.txt', '&'],
                                                            logfile='ShellSequenceLog', haltOnFailure=True),
                                            ]))
# BitBucketFactory.workdir = 'customDirName'
# Default is build in path /worker/<BuilderName>/build/<fetched files>


c['builders'] = []
c['builders'].append(util.BuilderConfig(
                                        name="BuilderOfQueryBuilder",
                                        workernames=["example-worker"],
                                        factory=BitBucketFactory,
                                        properties = {'owner': [
                                                    'foo@leadics.com'
                                                    ]
                                            }))

####### BUILDBOT SERVICES

c['services'] = []

c['services'].append(reporters.MailNotifier(fromaddr="buildbot@foo.com",
                                sendToInterestedUsers=True,
                                #extraRecipients=["foo@bar.com"],
                                useTls=True, relayhost="smtp.gmail.com",
                                smtpPort=587, smtpUser="buildbot@company.com",
                                smtpPassword="password"))


####### PROJECT IDENTITY



c['title'] = "BitBucket_BuildBot"
c['titleURL'] = "https://buildbot.github.io/hello-world/"



c['buildbotURL'] = "http://"+localhost+":8010/"

####### DB URL

c['db'] = {
    'db_url' : "sqlite:///state.sqlite",
}
  

hooks.py

from buildbot.www.hooks.bitbucketcloud import BitbucketCloudEventHandler

class CustomHandler(BitbucketCloudEventHandler):

    def handle_repo_push(self, payload):
        changes = []
        #project = payload['repository']['name']
        repo_url = payload['repository']['links']['self']['href']
        web_url = payload['repository']['links']['html']['href']

        for payload_change in payload['push']['changes']:
            if payload_change['new']:
                age = 'new'
                category = 'push'
            else:  # when new is null the ref is deleted
                age = 'old'
                category = 'ref-deleted'

            commit_hash = payload_change[age]['target']['hash']

            if payload_change[age]['type'] == 'branch':
                branch = GIT_BRANCH_REF.format(payload_change[age]['name'])
            elif payload_change[age]['type'] == 'tag':
                branch = GIT_TAG_REF.format(payload_change[age]['name'])

            change = {
                'revision': commit_hash,
                'revlink': '{}/commits/{}'.format(web_url, commit_hash),
                'repository': repo_url,
                'author': '{} <{}>'.format(payload['actor']['display_name'],
                                           payload['actor']['username']),
                'comments': 'Bitbucket Cloud commit {}'.format(commit_hash),
                'branch': branch,
                #'project': project,
                'category': category
            }

            if callable(self._codebase):
                change['codebase'] = self._codebase(payload)
            elif self._codebase is not None:
                change['codebase'] = self._codebase

            changes.append(change)

        return (changes, payload['repository']['scm'])

但仍然指向buildbot.www.hooks.bitbucketcloud的BitbucketCloudEventHandler 出现以下错误

2018-07-16 17:02:05+0530 [_GenericHTTPChannelProtocol,0,127.0.0.1] adding changes from web hook
    Traceback (most recent call last):
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/twisted/internet/defer.py", line 1532, in unwindGenerator
        return _inlineCallbacks(None, gen, Deferred())
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
        result = g.send(result)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/buildbot/www/change_hook.py", line 107, in getAndSubmitChanges
        changes, src = yield self.getChanges(request)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/twisted/internet/defer.py", line 1532, in unwindGenerator
        return _inlineCallbacks(None, gen, Deferred())
    --- <exception caught here> ---
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
        result = g.send(result)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/buildbot/www/change_hook.py", line 168, in getChanges
        changes, src = yield handler.getChanges(request)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/buildbot/www/hooks/bitbucketcloud.py", line 165, in getChanges
        return self.process(request)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/buildbot/www/hooks/bitbucketcloud.py", line 56, in process
        return handler(payload)
      File "/home/rajat/anaconda3/envs/buildbot/lib/python3.6/site-packages/buildbot/www/hooks/bitbucketcloud.py", line 75, in handle_repo_push
        project = payload['repository']['project']['name']
    builtins.KeyError: 'project'

我在做什么错? 我必须重写该类,因为bitbucket更改了其钩子json并删除了项目密钥。 任何帮助将不胜感激。

0 个答案:

没有答案