简体   繁体   中英

Calling Python method in BuildBot build Steps

I am new to BuildBot and trying to implement the build process from master.cfg.

I created common utility python packages which can be used while build-process,

So while adding steps in util.BuildFactory() I want to execute the python methods from my custom build-package.

I refereed the Adding customized functions to Buildbot .

I Imported my custom package in master.cfg in buildbot, But still not able to call that method directly from factory.addStep .

I have another alternative like create python script, import that custom-build utility package and then execute that script from steps.ShellCommand(command=['python', 'myScript.py'])

But there will be additional script maintains for particular build process and I can't reuse that script.

SO WHAT IS THE WAY TO CALL PYTHON METHOD FROM BUILD PROCESS OF BUILDBOT.

To execute python code you need to write custom build step - a class inherited from BuildStep with your code in run() method. Note that this code will be executed on master (as and ShellCommand from question). To execute code on slave you need to use RemoteShellCommand. See docs for all details.

To call custom python script from buildbot need some configuration changes in master.cfg

BUILDBOT INSTALLATION STEP

1] virtualenv -p python3 buildbotenv
2] mkdir ~/Documents/Buildbot/master
3] source buildbotenv/bin/activate
4] pip install --upgrade pip
5] pip install 'buildbot[bundle]'
6] buildbot create-master <Folder Name>
   buildbot create-master master
7] cp master/master.cfg.sample master/master.cfg
8] buildbot start master
9] pip install buildbot-worker
10] pip install setuptools-trial
11] buildbot-worker create-worker worker localhost example-worker pass
12] buildbot-worker start worker

master.cfg

from buildbot.plugins import *
from buildbot.plugins import steps, util

c = BuildmasterConfig = {}

####### WORKERS

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

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

####### CHANGESOURCES

c['change_source'] = []
c['change_source'].append(changes.GitPoller(
        'git://<GIT URL>',
        workdir='gitpoller-workdir', branch='bugfix',
        pollInterval=300))

####### SCHEDULERS

c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="all",
                            change_filter=util.ChangeFilter(branch='bugfix'),
                            treeStableTimer=None,
                            builderNames=["runtests"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="force",
                            builderNames=["runtests"]))

####### BUILDERS

factory = util.BuildFactory()
factory.addStep(steps.Git(repourl='git://<GIT URL>', mode='incremental'))
factory.addStep(steps.ShellCommand(command=["trial", "hello"],
                                   env={"PYTHONPATH": "."}))

c['builders'] = []

call_python_script = steps.ShellCommand(name="call_python_script",
                                    description="call_python_script",
                                    command="sh ~/Documents/Buildbot/deployment.py",
                                    haltOnFailure=True)                                    

f_simplebuild = util.BuildFactory()

#f_simplebuild.addStep(create_file)
f_simplebuild.addStep(call_python_script)

#This will be the comman 
c['builders'].append(
    util.BuilderConfig(name="runtests",
      workernames=["example-worker"],
      factory=f_simplebuild))

####### BUILDBOT SERVICES

c['services'] = []

####### PROJECT IDENTITY

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

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

# minimalistic config to activate new web UI
c['www'] = dict(port=8010,
                plugins=dict(waterfall_view={}, console_view={}, grid_view={}))

####### DB URL

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM