python工具是什么-python有什么好用的持续集成工具么?

python的有比较强悍,google等公司在用的构建框架buidbot。另外python也有jenkins API。

python相关的库参考下:

buildbot - google等公司使用的持续集成框架,上手比Jenkins难,功能和性能远比Jenkins强大。 链接 python库介绍-buildbot教程

BitBake – 嵌入式Linux上类似make工具。链接

buildout – 用于从多个部分创建,组装和部署应用程序的构建系统。链接

PlatformIO – 在不同的开发平台的控制台构建工具。链接

PyBuilder – 纯Python编写的持续构建工具。链接

SCons – 软件构建工具。链接

jenkinsapi – Hudson & Jenkins python API。链接

另外我个人觉得python一个强悍的地方在于很容易自行开发出构建工具, 参见 china-testing/python-api-tesing以下python库在自行开发构建工具时比较常用。

DevOps工具(DevOps Tools)DevOps的软件和库。*

Ansible - 极其简单的IT自动化平台。 --推荐

Cloud-Init - 处理云实例的早期初始化的多分发包。

cuisine - 为 Fabric 提供一系列高级函数。

Fabric - 简单的Pythonic远程执行和部署工具。 --推荐

Fabtools - 编写真棒Fabric文件的工具。

nova - OpenStack计算。 --推荐

swift - OpenStack存储。 --推荐

pexpect - 在像GNU expect这样的伪终端中控制交互式程序。 --强烈推荐

psutil - 跨平台的进行和系统实用程序模块。 --推荐

SaltStack - 基础设施自动化和管理系统。 --推荐

supervisor - 用于UNIX的Supervisor进程控制系统。

gitapi:Git 的纯 Python API。官网

hgapi:Mercurial 的纯 Python API。官网

honcho:Foreman 的 Python 克隆版,用来管理基于 Procfile 的应用。官网

全栈 Web 框架。Django:Python 界最流行的 web 框架。链接 wesome-django系列 链接 --强烈推荐

Flask:Python 微型框架。链接 awesome-flask系列 链接 --强烈推荐 python web框架第一名

pyramid:一个小巧,快速,接地气的开源Python web 框架。链接 awesome-pyramid系列 链接

Bottle:一个快速小巧,轻量级的 WSGI 微型 web 框架。链接 --推荐

CherryPy:一个极简的 Python web 框架,支持HTTP/1.1 协议且具有WSGI 线程池。链接

sanic:python3 快速的web服务器,类似flask。链接 --推荐

web.py:既简单,又强大的web 框架。链接

TurboGears:易于扩展的全栈微框架。链接

web2py:全栈 web 框架和平台,用于安全数据库访问的web用。链接

Tornado - web 框架和异步网络库. 链接人工智能医药中医:python库介绍-buildbot教程​zhuanlan.zhihu.comzhihu-card-default.svg

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

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

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

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

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

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

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

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

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

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

缺点:buildbot对多项目支持并不好。参考资料:

安装

目的

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

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

准备

#!python

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' This parameter helps the buildbot development team to understand the installation base.'

b' No personal information is collected.'

b' Only installation software version info and plugin usage is sent.'

b' You can `opt-out` by setting this variable to None.'

b' Or `opt-in` for more information by setting it to "full".'

b' '

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

欢迎 关注 点赞,谢谢!

zhouaimei1​www.zhihu.comda8e974dc_ipico.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jenkins是一个开源的持续集成工具,它可以用于自动化构建、测试和部署软件项目。使用Jenkins可以轻松地设置和管理持续集成流程。 要在Python项目中使用Jenkins进行持续集成,首先需要在Jenkins服务器上安装Python环境和相关插件。然后,可以按照以下步骤进行配置: 1. 创建一个新的Jenkins任务:在Jenkins中,点击"New Item"创建一个新的任务,并选择"Freestyle project"。 2. 配置源代码管理:在"配置"选项卡中,选择你的代码仓库类型(如Git、SVN等),并填写相关的仓库地址和认证信息。 3. 配置构建步骤:在"构建"选项卡中,选择"Add build step"并选择相应的构建步骤,如执行Shell命令或者运行Python脚本。 4. 配置构建触发器:在"构建触发器"选项卡中,选择适合你项目的触发条件,如定时触发或者代码变更触发。 5. 配置构建后操作:在"构建后操作"选项卡中,选择适合你项目的操作,如发送邮件通知或者部署到其他服务器。 完成以上配置后,保存并触发构建即可开始持续集成流程。Jenkins会自动拉取代码、执行构建步骤,并根据你的配置进行相应的操作。 需要注意的是,为了实现更高级的持续集成功能,可以结合其他工具和插件使用,如使用Jenkins的Pipeline插件来定义更复杂的构建流程,或者使用Jenkins的插件来集成代码质量检查工具和自动化测试工具。 希望以上信息对你有所帮助!如果你有任何其他问题,请随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值