CI/CD工具
pip3 install buildbot
pip3 install buildbot-www
pip3 install buildbot-grid-view
pip3 install buildbot-console_view
pip3 install buildbot-worker
pip3 install setuptools-trial
创建master
#!python
$ buildbot create-master master
mkdir /opt/master
creating /opt/master/master.cfg.sample
creating database (sqlite:///state.sqlite)
buildmaster configured in /opt/master
$ mv master/master.cfg.sample master/master.cfg
$ buildbot start master
Following twistd.log until startup finished…
The buildmaster appears to have (re)started correctly.
日志在master/twistd.log
此时访问 http://localhost:8010/
创建worker
#!python
$ buildbot-worker create-worker worker localhost example-worker pass
mkdir /opt/worker
mkdir /opt/worker/info
Creating info/admin, you need to edit it appropriately.
Creating info/host, you need to edit it appropriately.
Not creating info/access_uri - add it if you wish
Please edit the files in /opt/worker/info appropriately.
worker configured in /opt/worker
$ buildbot-worker start worker
Following twistd.log until startup finished…
The buildbot-worker appears to have (re)started correctly.
日志在worker/twistd.log
快速入门
本章从china-testing拉取代码,调用pytest执行buildbot/hello-world/hello下的单元测试。
配置项目名和URL
#!python
$ vi master/master.cfg
# -*- python -*-
# ex: set filetype=python:
from buildbot.plugins import *
# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.
# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}
####### WORKERS
# The 'workers' list defines the set of recognized workers. Each element is
# a Worker object, specifying a unique worker name and password. The same
# worker name and password must be configured on the worker.
c['workers'] = [worker.Worker("example-worker", "pass")]
# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
# could connect to your master with this protocol.
# 'port' must match the value configured into the workers (with their
# --master option)
c['protocols'] = {'pb': {'port': 9989}}
####### CHANGESOURCES
# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes. Here we point to the buildbot version of a python hello-world project.
c['change_source'] = []
c['change_source'].append(changes.GitPoller(
'git://github.com/china-testing/python-api-tesing.git',
workdir='gitpoller-workdir', branch='master',
pollinterval=300))
####### SCHEDULERS
# Configure the Schedulers, which decide how to react to incoming changes. In this
# case, just kick off a 'runtests' build
c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
name="all",
change_filter=util.ChangeFilter(branch='master'),
treeStableTimer=None,
builderNames=["runtests"]))
c['schedulers'].append(schedulers.ForceScheduler(
name="force",
builderNames=["runtests"]))
####### BUILDERS
# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which workers can execute them. Note that any particular build will
# only take place on one worker.
factory = util.BuildFactory()
# check out the source
factory.addStep(steps.Git(repourl='git://github.com/china-testing/python-api-tesing.git', mode='incremental'))
# run the tests (note that this will require that 'trial' is installed)
factory.addStep(steps.ShellCommand(command=["pytest", "buildbot/hello-world/hello"]))
c['builders'] = []
c['builders'].append(
util.BuilderConfig(name="runtests",
workernames=["example-worker"],
factory=factory))
####### BUILDBOT SERVICES
# 'services' is a list of BuildbotService items like reporter targets. The
# status of each build will be pushed to these targets. buildbot/reporters/*.py
# has a variety to choose from, like IRC bots.
c['services'] = []
####### PROJECT IDENTITY
# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').
c['title'] = "Hello World CI"
c['titleURL'] = "https://github.com/china-testing/python-api-tesing"
# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.
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'] = {
# This specifies what database buildbot uses to store its state. You can leave
# this at its default for all but the largest installations.
'db_url' : "sqlite:///state.sqlite",
}
$ $ buildbot reconfig master
sending SIGHUP to process 4194
b'2018-01-24 15:13:07+0800 [-] beginning configuration update'
b"2018-01-24 15:13:07+0800 [-] Loading configuration from '/opt/master/master.cfg'"
b'2018-01-24 15:13:07+0800 [-] /usr/local/lib/python3.5/dist-packages/buildbot/config.py:102: buildbot.config.ConfigWarning: [0.9.0 and later] `buildbotNetUsageData` is not configured and defaults to basic.'
b'\tThis parameter helps the buildbot development team to understand the installation base.'
b'\tNo personal information is collected.'
b'\tOnly installation software version info and plugin usage is sent.'
b'\tYou can `opt-out` by setting this variable to None.'
b'\tOr `opt-in` for more information by setting it to "full".'
b'\t'
b"2018-01-24 15:13:07+0800 [-] gitpoller: using workdir '/opt/master/gitpoller-workdir'"
b"2018-01-24 15:13:08+0800 [-] initializing www plugin 'waterfall_view'"
b"2018-01-24 15:13:08+0800 [-] initializing www plugin 'console_view'"
b"2018-01-24 15:13:08+0800 [-] initializing www plugin 'grid_view'"
b'2018-01-24 15:13:08+0800 [-] configuration update complete'
Reconfiguration appears to have completed successfully
首次构建
打开:http://localhost:8010/#/builders
点击右上角的force,表单可以什么都不填,点击“Start Build”就会开始构建。
很快可以看到输出:
#!python
SESSION=ubuntu
SESSIONTYPE=gnome-session
SESSION_MANAGER=local/andrew-MS-7A71:@/tmp/.ICE-unix/2824,unix/andrew-MS-7A71:/tmp/.ICE-unix/2824
SHELL=/bin/bash
SHLVL=1
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
TERM=xterm
TMDB_API_KEY=ee6623075bcc5519ef16be16e1f139e7
UPSTART_EVENTS=xsession started
UPSTART_INSTANCE=
UPSTART_JOB=unity7
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/2570
USER=andrew
XAUTHORITY=/home/andrew/.Xauthority
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
XDG_CURRENT_DESKTOP=Unity
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/var/lib/snapd/desktop
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/andrew
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/1000
XDG_SEAT=seat0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_ID=c2
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_TYPE=x11
XDG_VTNR=7
XMODIFIERS=@im=fcitx
_=/usr/local/bin/buildbot-worker
using PTY: False
============================= test session starts ==============================
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /opt/worker/runtests/build/buildbot/hello-world, inifile:
collected 2 items
buildbot/hello-world/hello/test_hello.py ..
=========================== 2 passed in 0.01 seconds ===========================
program finished with exit code 0
elapsedTime=0.168047