Jenkins是Java编写的开源的持续集成工具。在与Oracle发生争执后从Hudson项目复制而成。
Jenkins提供了软件开发的持续集成服务。它是运行在Servlet容器(例如Apache Tomcat)的服务器。它支持软件配置管理(SCM)工具(包括AccuRev SCM、CVS、Subversion、Git、Perforce、Clearcase和RTC等),可以执行基于Apache Ant和Apache Maven的项目,以及任意的Shell脚本和Windows批处理命令。Jenkins的主要开发者是Kohsuke Kawaguchi。Jenkins是在MIT许可证下发布的自由软件。
可以通过各种手段触发构建。例如提交给版本控制系统时被触发,也可以通过类似Cron的机制调度,也可以在其他的构建已经完成时,还可以通过特定的URL进行请求。类似的软件有Buildbot、Tox等,另外python中的Django-Jenkins也有一定知名度。
下面是python中使用较多的jenkins相关库:
https://pypi.python.org/pypi/jenkinsapi A Python API for accessing resources on a Jenkins continuous-integration server. 使用最多的python jenkins库。
月下载:6万多
文档:https://github.com/salimfadhley/jenkinsapi
安装:pip install jenkinsapi
用法:
>>> import jenkinsapi >>> from jenkinsapi.jenkins import Jenkins >>> J = Jenkins(‘http://localhost:8080‘) >>> J.version 1.542 >>> J.keys() # Jenkins objects appear to be dict-like, mapping keys (job-names) to [‘foo‘, ‘test_jenkinsapi‘] >>> J[‘test_jenkinsapi‘] <jenkinsapi.job.Job test_jenkinsapi> >>> J[‘test_jenkinsapi‘].get_last_good_build() <jenkinsapi.build.Build test_jenkinsapi #77>
https://pypi.python.org/pypi/jenkins-job-builder Manage Jenkins jobs with YAML
月下载:1万多
文档:http://python-jenkins.readthedocs.org/en/latest/
https://pypi.python.org/pypi/python-jenkins Python bindings for the remote Jenkins API
月下载:3万多
文档:http://python-jenkins.readthedocs.org/en/latest/
https://pypi.python.org/pypi/jenkins-autojobs Scripts for automatically creating Jenkins jobs from SCM branches
月下载:2千多
文档:http://jenkins-autojobs.readthedocs.org/en/latest/
https://pypi.python.org/pypi/jenkins-job-builder-naginator Automatically reschedule a build after a build failure.
文档:jenkins-job-builder-naginator.readthedocs.org
月下载:5千多
https://pypi.python.org/pypi/django-jenkins Plug and play continuous integration with django and jenkins
文档:jenkins-job-builder-naginator.readthedocs.org
月下载:2万多
https://pypi.python.org/pypi/autojenkins Jenkins Remote Control Library
月下载:2千多
文档:http://pythonhosted.org/autojenkins/
另外通过python plugin: https://wiki.jenkins-ci.org/display/JENKINS/Python+Plugin可以直接执行python代码。
jenkins常见的使用流程如下:
Jenkins有千余插件,详细列表参见:https://wiki.jenkins-ci.org/display/JENKINS/Plugins。插件教程参见:https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial。插件下载:https://updates.jenkins-ci.org/download/plugins/。
进入https://jenkins-ci.org/,在右侧的Native packages下面选择对应的操作系统,这里以Centos为例。点击Centos链接,进入http://pkg.jenkins-ci.org/redhat/。网页的黑底部分即jenkins的安装方法。
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key yum install jenkins
通过“ps afx | grep jenkins.war | grep -v grep“查看jenkins.war相关的进程是否启动,如果没有启动,执行"service jenkins start", 现在在浏览器通过“http://localhost:8080“即可访问jenkins。
更多资料参见:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions
注意jenkins当前版本(1.638)要求java 1.7以上的版本。且不能使用centos默认的openjdk,到http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html下载对应的Linux rpm包安装。
这里我们添加一个git项目。
“ Manage Jenkins" -> "Manage Plugins" -> "Available", 输入 github :
注意上面步骤输入github之后,不要按回车或者搜索框,jenkins会自动搜索。选中上面2个,点击" Click the che Download now and install after restart", 然后重启 Jenkins。
创建Freestyle project:
在"Source Code Management"中配置Git:
在“Add build step"中选“ Invoke Ant “
执行编译:
查看控制台输出:
查看Workspace页面:
大功告成!
https://wiki.centos.org/HowTos/Subversion
原文:http://www.cnblogs.com/pythontesting/p/4970808.html