jenkins与持续集成_与Jenkins的持续集成,第1部分

jenkins与持续集成

Continuous integration is a software quality control technique that checks code integrity whenever small changes are made rather than waiting for all of the code to be finished before testing and debugging it.

持续集成是一种软件质量控制技术,该技术可在进行任何小的更改时检查代码的完整性,而不是在测试和调试代码之前等待所有代码完成。

CI asks for version control and for automated unit testing and constant package building. In principle, the automated part of the cycle can be done with cron jobs that trigger programs like xunit (tester) and make (builder). However, more convenient and resourceful tools have emerged in the last few years, like Jenkins, which is combines automation and supervisory tasks into one single system.

CI要求版本控制以及自动化的单元测试和持续的软件包构建。 原则上,周期的自动化部分可以通过cron作业来完成,这些作业会触发诸如xunit(测试程序)和make(生成程序)之类的程序。 但是,最近几年出现了更方便,更灵活的工具,例如Jenkins,该工具将自动化和监管任务组合到一个系统中。

What Jenkins does is not difficult to understand once you know why it does that. In this 2-part series I’ll present a big-picture overview of the sort of programming problems CI can solve, show how it can be achieved with the help of specialized software and explain how Jenkins can be minimally used to periodically trigger testing and building of PHP (web)applications, keeping a record of where integration succeeded or failed and maintaining an “output” folder up-to-date with the latest files that the application requires, ready to be uploaded to the server.

一旦知道了它的作用,詹金斯所做的事情就不难理解。 在这个由两部分组成的系列文章中,我将概述CI可以解决的各种编程问题,展示如何借助专用软件来实现它,并说明如何最小化使用Jenkins定期触发测试和构建PHP(web)应用程序,记录集成成功或失败的位置,并维护一个“输出”文件夹,其中包含应用程序所需的最新文件的最新信息,可随时上传到服务器。

By the way, I do not have to be concerned with making the reader an expert in Jenkins because it is so easy to use that once its basic purpose is understood the sophisticate resources follow naturally.

顺便说一句,我不必担心让读者成为詹金斯专家,因为它是如此容易使用,以致一旦理解了其基本目的,那么自然而然的资源就会自然而然地出现。

大图景 (The Big Picture)

Implementing its early retirement program, The One Big Worldwide Corporation, Inc. offered its employees suggestions on how to use their new quality time. One was programming for the web whether for fun, community service, or as a small business of their own. Several people showed interest and the training department bought them a series of very nice books on all aspects of web design and development published by an Australian company who also maintains some of the world’s finest websites on the subject.

为实施提前退休计划,The One Big Worldwide Corporation,Inc.向员工提供了有关如何利用新的优质时间的建议。 一种是为娱乐,社区服务或作为自己的小型企业的网络编程。 几个人表现出兴趣,培训部门为他们购买了一系列非常不错的书,这些书是由一家澳大利亚公司出版的,涉及网页设计和开发的各个方面,该公司还维护着有关该主题的一些世界上最好的网站。

Among those who jumped into PHP programming for the web were three former foreign trade operators who, having worked often together in the past, decided to set up an on-line network of former employees: Bertha, who lives in Buenos Aires, Argentina, Alicia, who resides in Yokohama, Japan, and Miwa from Bonn, Germany. Also, Guido, the former HR man in Torino, Italy, decided to create his own web development and hosting business.

跳到网络上进行PHP编程的人中,有三位以前的外贸操作员,他们过去经常在一起工作,因此决定建立一个由前雇员组成的在线网络:伯塔(Bertha)居住在阿根廷布宜诺斯艾利斯,艾丽西亚(Alicia) ,分别居住在日本的横滨和德国波恩的Miwa。 另外,意大利都灵的前人力资源专员Guido决定创建自己的网站开发和托管业务。

To get started with their networking application, Bertha offered to write the database searching script while Alicia volunteered to develop the HTML interface and Miwa decided to attack the code for adding/editing/deleting records. They agreed to meet on-line once a week to test out their results. The first couple of weeks things went smooth but soon after problems arose as Bertha decided that naming variables in did not look good and changed everything to , Alicia renamed some of the interface form fields and Miwa changed the way the database dealt with dates. When they got together and tested the application, errors began to pop out as corn from the One Big Worldwide Corporation’s One and Only Famous Popcorn Machine.

为了开始使用他们的网络应用程序,Bertha提出编写数据库搜索脚本,而Alicia自愿开发HTML界面,而Miwa决定攻击用于添加/编辑/删除记录的代码。 他们同意每周一次在线见面以测试结果。 最初的几周情况一直很顺利,但问题很快出现,因为Bertha认为中的命名变量看起来不好,并将所有内容更改为 ,Alicia重命名了一些接口表单字段,而Miwa更改了数据库处理方式日期。 当他们聚在一起测试应用程序时,错误开始从One Big Worldwide Corporation的“唯一且著名的爆米花机”中弹出。

Meanwhile in Italy, Guido was having a hard time keeping track of the development files scattered all over his hard drive, some newer and some older than the versions on his clients’ servers, so that fixing a problem on one website invariably broke another.

与此同时,在意大利,Guido很难跟踪分散在他的硬盘驱动器上的开发文件,这些开发文件比其客户服务器上的更新版本高一些,因此,解决一个网站上的问题总是会破坏另一个网站。

The ladies and Guido were in what is sometimes called “integration hell” out of which the way is lots of praying to St Isidore, taken by some as the patron saint of the Internet, or continuous integration.

女士们和Guido处于有时被称为“整合地狱”的地方,从其中走了很多路向圣伊西多尔祈祷,有人将其视为互联网的守护神,或者是持续融合。

Continuous integration (CI) is a development method where any change, no matter how small, to a file must be documented, tested, and sent to a central version-controlled repository and packages are built in a planned manner, leaving out everything that is not required to run the application.

持续集成(CI)是一种开发方法,其中对文件的任何更改(无论大小)都必须记录,测试并发送到中央版本控制的存储库,并且以计划的方式构建软件包,而忽略所有不需要运行该应用程序。

Continuous integration helps make sure that everybody is working on the latest version of code, that no unannounced changes in file A compromises the development of file B, that at most a few corrections are at any time required to get B back into working with A and that packages are self-contained, neatly organized, and free of unnecessary intermediate files.

持续集成有助于确保每个人都在使用最新版本的代码,文件A中没有发生未经通知的更改不会损害文件B的开发,并且在任何时候最多都需要进行一些更正才能使B重新与A一起使用,并且软件包是独立的,井井有条的,并且没有不必要的中间文件。

版本控制 (Version Control)

After reading Sean Hudgston’s excellent article Introduction to Git, which I recommend to those that still need to get acquainted with this terrific tool (I mean, now!), the ladies and Guido decided to use Linus Torvalds’ repository manager Git to try to get all their code organized in one place. As he worked alone, Guido set up a repository on his desktop machine creating an umbrella directory () with a subfolder for each project, like , and .

在阅读了Sean Hudgston的出色文章《 Git简介》之后 ,我向仍然需要了解这一出色工具的人推荐(我是说,现在!),女士们和Guido决定使用Linus Torvalds的存储库管理器Git来尝试获得该工具。他们所有的代码都放在一个地方。 当Guido独自工作时,他在台式机上建立了一个存储库,为每个项目创建了一个伞形目录( )及其子文件夹,例如和 。

The ladies needed a remote repository that everyone could access, and they opted for a GitHub account creating a project they called “former_employee_net” and agreeing that everyone would a file as soon as its creation or editing was finished.

女士们需要一个所有人都可以访问的远程存储库,他们选择了一个GitHub帐户来创建一个名为“ former_employee_net”的项目,并同意每个人都将在文件创建或编辑完成后立即文件。

单元测试 (Unit Testing)

The fundamental step in testing software is continuously checking whether new code works as it is supposed to before committing it to the Git repository. This is called unit testing, and it can be carried out in PHP with the help of Sebastian Bergmann’s PHPUnit framework.

测试软件的基本步骤是在将新代码提交到Git存储库之前,不断检查新代码是否按预期工作。 这称为单元测试 ,可以在Sebastian Bergmann的PHPUnit框架的帮助下在PHP中执行。

Apparently it was Miwa who read my colleague Michelle Sanver’s Getting Started with PHPUnit and began to write tests for her part of the application. This proved a success and was soon imitated by the others.

显然是Miwa读了我的同事Michelle Sanver的《 PHPUnit入门》,并开始为她的应用程序部分编写测试。 这证明是成功的,并很快被其他人模仿。

建造 (Building)

Once code was shown to be functional and was committed to the repository, there was the matter of creating packages for easy deployment to the production server, by separating the files that were needed for the application to run from those used to support development.

一旦证明代码可以正常工作并提交给存储库,就可以通过将应用程序运行所需的文件与支持开发的文件分开来创建易于部署到生产服务器的软件包。

Put in charge of that for the ladies’ team, Alicia wrote down a list of file types to be left out (like .xcf files for Gimp image projects) and a list of those (like .php and .png) to be included in the compressed file. That was easy, but error-prone.

由女士团队负责的是,Alicia写下了要忽略的文件类型列表(例如Gimp图像项目的.xcf文件)以及要包含在其中的文件类型列表(例如.php和.png)。压缩文件。 那很容易,但是容易出错。

Apache Ant runs a batch of tasks otherwise done one-by-one. It reads a user-created script with actions like “copy this to there” and “delete that from here”. Guido was already using it, and he referred Alicia to the Ant tutorial on Apache’s website. Very shortly she created her own script and began automating not only the builds but also the testing.

Apache Ant运行着一批任务,否则它们是一个接一个地完成的。 它读取用户创建的脚本,并带有“将其复制到此处”和“从此处删除”之类的操作。 Guido已经在使用它,他将Alicia推荐给Apache网站上的Ant教程。 很快,她创建了自己的脚本,不仅开始自动进行构建,还开始进行测试自动化。

监理 (Supervision)

In theory it all works fine, but, Alas, poor Yorick!, in practice other problems soon arose. Miwa missed some unit tests causing the group to spend time on bad code that eventually had to be fixed. By his turn, just to be on the safe side, Guido was spending a lot of time repeating tests he wasn’t sure he did or not.

从理论上讲,一切正常,但是可惜的是,可怜的Yorick!在实践中很快出现了其他问题。 Miwa错过了一些单元测试,这导致该小组花时间在错误的代码上,最终不得不加以修复。 轮到他时,为了安全起见,Guido花费了大量时间重复他不确定自己是否做过的测试。

And both the group and the lone developer forgot more than once to build a package which resulted in older, broken versions of some files finding their way on the production servers. That’s where a supervisory tool came in.

小组和唯一的开发人员都忘记了一次以上的构建软件包的过程,结果导致某些文件的旧版本,破损版本在生产服务器上找到了路。 那是一种监督工具。

詹金斯 (Jenkins)

Created at Sun Microsystems by Kohsuke Kawaguchi, who seemed to have had enough of manual integrations, Jenkins began life as Hudson, a CI automation supervisory environment written in Java. With Sun’s absorption by Oracle, the community changed the name from Hudson to Jenkins which amounted to a de facto forking.

Jenkins由似乎已经进行了手动集成的川口晃介(Kohsuke Kawaguchi)在Sun Microsystems创立,Jenkins最初以Hudson(使用Java编写的CI自动化监管环境)的生活开始。 随着Sun被Oracle吸收,该社区将名称从Hudson更改为Jenkins,这实际上是一个分支。

Jenkins, and for that matter Hudson, looks after the running of various tasks required by CI while helping to improve coding style, looking for duplicate code and statements that seems needlessly complex. Jenkins was created for Java development but with the help of plugins now it can render services to many programming languages.

詹金斯(Jenkins)和哈德森(Hudson)负责运行CI所需的各种任务,同时帮助改善编码风格,寻找看起来不必要的重复代码和语句。 Jenkins是为Java开发而创建的,但是现在借助插件,它可以为多种编程语言提供服务。

In the second part of this article we will install and set Jenkins up to control the periodical test and build of a simple PHP project, which also requires version control, unit testing and build automation programs. We’ll end this first part by installing those.

在本文的第二部分中,我们将安装并设置Jenkins来控制一个简单PHP项目的定期测试和构建,这也需要版本控制,单元测试和构建自动化程序。 我们将通过安装这些结束第一部分。

Git,PHPUnit和Apache Ant (Git, PHPUnit AND Apache Ant)

Before we can use Jenkins with our PHP demonstration project, we need to install Git (revision control system), PHPUnit (unit tester for PHP) and Apache Ant (package builder).

在将Jenkins用于我们PHP演示项目之前,我们需要安装Git(版本控制系统),PHPUnit(PHP的单元测试器)和Apache Ant(程序包生成器)。

Git is available in Linux code reps and their website offers installers for Mac and Windows. Once installed, check it by typing:

Git在Linux代码代表处可用, 其网站提供Mac和Windows的安装程序。 安装后,通过键入以下内容进行检查:

PHPUnit should be installed with the help of PEAR, the PHP extension and application repository, no other way. In Linux make sure your PEAR is the latest stable version and run:

应该使用PEAR,PHP扩展和应用程序存储库来安装PHPUnit,没有其??他方法。 在Linux中,确保您的PEAR是最新的稳定版本并运行:

After the usual installation progress output is over, check it works:

在常规安装进度输出结束后,检查其是否有效:

Apache Ant is Java software too and do not need an installer. The binaries packages are available from their download page. Major Linux distributions may have packages in their repos. Once you have installed it, again, run a test from the command-line interface:

Apache Ant也是Java软件,不需要安装程序。 二进制程序包可从其下载页面获得 。 主要的Linux发行版可能在其仓库中包含软件包。 安装完毕后,再次从命令行界面运行测试:

Note that Ant requires only one dash before the option “version”!

请注意,Ant只需在选项“版本”前加一个破折号!

At this point we have all we need except Jenkins itself which will be covered in the second part of this article. Until then, take care!

至此,除了詹金斯本身之外,我们已经拥有所有需要的东西,本文第二部分将对此进行介绍。 在此之前,请保重!

Image via Charles Taylor / Shutterstock

图片来自Charles Taylor / Shutterstock

翻译自: https://www.sitepoint.com/continuous-integration-with-jenkins-1/

jenkins与持续集成

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览91337 人正在系统学习中 相关资源:android实现手机摇晃摆动效果_android开发-Android代码类资源…

来源:culh2177

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年7月8日
下一篇 2020年7月9日

相关推荐