[雪峰磁针石博客]构建工具buildbot教程 持续交付与构建

简介: Buildbot是python实现的开源持续构建和持续交付工具,为Python, Mozilla, Chromium, WebKit等知名项目使用。 与Jenkins相比,Buildbot在大陆使用者较少。

Buildbot是python实现的开源持续构建和持续交付工具,为Python, Mozilla, Chromium, WebKit等知名项目使用。

与Jenkins相比,Buildbot在大陆使用者较少。原因在于Jenkins的界面相对较美观,更容易上手;Jenkins的中文文档比较丰富。但是Jenkins因为资源消耗庞大、不太方便定制而不受一些有实力的公司欢迎。这些不少把目光聚焦在Buildbot。

究竟Buildbot有哪些优点让这些公司青睐呢?Buildbot基于python网络框架Twisted,分布式做得好。Buildbot可以直接使用python包,轻松拥有上万库,具备强大的扩展能力。如果你觉得Jenkins已经轻松地满足你的需求,你不需要Buildbot。如果你在Jenkins时觉得效率低下、扩展困难、一些用python等脚本可以实现的动作在Jenkins困难重重,那么可以看看Buildbot。

python的buildbot站点: http://buildbot.python.org/all/#/

Buildbot是开源的自动化软件构建,测试,发布流程的框架。

Buildbot支持跨平台,分布式,并行执行jobs,与版本控制系统的灵活集成,丰富的状态报告等等。

Buildbot是一个作业调度系统:它会对作业进行排队,在所需要的资源可用时执行任务,并报告结果。

Buildbot有一个或多个主机和从机。主机监控源代码库的变化,调配从机,并给用户和开发者报告结果。从机可在多种操作系统上运行。

可以配置Python脚本到主机。这个脚本可以简单到只配置内置组件,也可以充分发挥python所长,可以动态生成的配置,定制的组件及其他任何你能想到的。

该框架基于Twisted实现,并与所有主要的操作系统兼容。

Buildbot支持持续集成,持续部署,发布管理等的。Buildbot支持持续集成测试,自动化复杂的编译系统,应用程序部署和复杂的软件发布流程管理。比CruiseControl或Jenkins更适合混合语言的环境。在 Chromium,WebKit, Firefox, Python和Twisted等有广泛的使用。

缺点:buildbot对多项目支持并不好。

参考资料

安装

目的

本教程从零开始,尽可能快地运行您的第一个buildbot master和worker,而不会更改默认配置。

本教程假设您正在运行Linux,但可能适用于Windows。

准备


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


$ 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/

image.png

创建worker


$ 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


$ 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”就会开始构建。

image.png

很快可以看到输出:


  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

相关文章
|
设计模式 SpringCloudAlibaba 负载均衡
每天打卡,跟冰河肝这些项目,技术能力嗖嗖往上提升
前几天,就有不少小伙伴问我,冰河,你星球有哪些项目呢?我想肝你星球的项目,可以吗?今天,我就给大家简单聊聊我星球里有哪些系统性的项目吧。其实,每一个项目的价值都会远超门票。
160 0
每天打卡,跟冰河肝这些项目,技术能力嗖嗖往上提升
|
运维 关系型数据库 MySQL
九五从零开始的运维之路(其三十五)
MHA(MasterHigh Availability)是一套优秀的MySQL高可用环境下故障切换和主从复制的软件。 MHA 的出现就是解决MySQL 单点的问题。 MySQL故障切换过程中,MHA能做到0-30秒内自动完成故障切换操作。 MHA能在故障切换的过程中最大程度上保证数据的一致性,以达到真正意义上的高可用。
68 2
|
消息中间件 设计模式 Java
如何高效地阅读源码,我总结了18条心法,助你修炼神功
大家好,我是三友~~ 这篇文章我准备来聊一聊如何去阅读开源项目的源码。 在聊如何去阅读源码之前,先来简单说一下为什么要去阅读源码,大致可分为以下几点原因: - 最直接的原因,就是面试需要,面试喜欢问源码,读完源码才可以跟面试官battle - 提升自己的编程水平,学习编程思想和和代码技巧 - 熟悉技术实现细节,提高设计能力 - ...
如何高效地阅读源码,我总结了18条心法,助你修炼神功
|
存储 运维 Linux
九五从零开始的运维之路(其三十一)
计划任务是在指定的时间间隔内自动执行的任务。在Linux系统中,常用的计划任务工具是crond(cron daemon)。用户可以通过创建计划任务来定期执行指定的命令或脚本。
61 0
|
JSON 前端开发 JavaScript
解放双手!推荐一款阿里开源的低代码工具,YYDS
之前分享过一些低代码相关的文章,发现大家还是比较感兴趣的。之前在我印象中低代码就是通过图形化界面来生成代码而已,其实真正的低代码不仅要负责生成代码,还要负责代码的维护,把它当做一站式开发平台也不为过!最近体验了一把阿里开源的低代码工具LowCodeEngine,确实是一款面向企业级的低代码解决方案,推荐给大家! LowCodeEngine简介 LowCodeEngine是阿里开源的一套面向扩展设计的企业级低代码技术体系,目前在在Github上已有4.7K+Star。这个项目大概是今年2月中旬开源的,两个月不到收获这么多Star,确实非常厉害!
|
Java 测试技术 数据库
[雪峰磁针石博客]软件自动化测试初学者忠告
题外话 测试入门 很多受过高等教育的大学生经常问要不要去报测试培训班来入门测试。 答案是否。 高等教育的合格毕业生要具备自学能力,如果你不具备自学能力,要好好地反省一下,为什么自己受了高等教育迷恋于各种入门级别的培训?是没有毅力还是不知道学习方法? 没有毅力的话,要自己多看些励志的书,多想想社会的残酷,亲人的失望等来勉励自己,毕竟企业多半也不会喜欢懒散的人的。
|
测试技术
[雪峰磁针石博客]2018软件测试标准汇总下载
标题有链接的,点击标题即可下载 国际标准 ISO/IEC 25010 系统和软件质量模型 英文原版: BS ISO IEC 25010-2011 Systems and software engineering — Systems and software Quality Requirement.
|
测试技术 API Android开发
[雪峰磁针石博客]软件测试专家工具包3移动端
UI Automator UI Automator提供了一组API来构建基于交互UI的测试。API允许你执行操作,如打开设置菜单,非常适合黑盒自动化测试,在测试代码不依赖于应用的内部实现 uiautomatorviewer提供了一个方便的图形用户界面进行扫描和分析在Android设备上当前显示的UI组件。
|
测试技术 Linux Shell
[雪峰磁针石博客]自动化测试框架pytest教程1-快速入门
第1章 快速入门 什么是pytest? pytest是强大的Python测试工具,它可以用于所有类型和级别的软件测试。 Pytest可以被开发团队,QA团队,独立测试小组,实践TDD的个人和开放源代码项目。