Quickly build a continuous integration environment based on Jenkins

Source: Internet
Author: User

Label:

Continuous integration is a software development practice, which provides a theoretical basis for improving the efficiency of software development and guaranteeing the quality of software development. Jenkins is an open source software project designed to provide an open and easy-to-use software platform that makes continuous integration possible. This paper starts with the basic concept of continuous integration, and through concrete examples, describes how to quickly build continuous integration environment based on Jenkins.

Continuous integration Overview What is continuous integration

With the increasing complexity of software development, how to work well together among team members to ensure the quality of software development has gradually become an unavoidable problem in the development process. Especially in recent years, agile is becoming more and more prosperous in the field of software engineering, and how to adapt and guarantee the quality of software in the changing demand is especially important.

Continuous integration is a software development practice for this kind of problem. It advocates that team development members must often integrate their work, and even multiple integrations can occur on a daily basis. Each integration is validated through automated builds, including automated compilation, publishing, and testing, to quickly identify integration errors and enable teams to develop cohesive software faster.

The core value of continuous integration is:

    1. Any part of continuous integration is done automatically, without too much manual intervention, to reduce the duplication process to save time, expense and workload;
    2. Continuous integration ensures that the code submitted by team members at each point in time can be successfully integrated. In other words, at any point in time can find the first time the integration of software issues, so that the release of deployable software at any time becomes possible;
    3. Continuous integration also facilitates the development of the software itself, which is particularly important in scenarios where demand is unclear or frequently changed, and the quality of continuous integration helps teams make effective decisions while building team confidence in developing products.
Principles of Continuous integration

The principles of continuous integration, which are universally recognized by the industry, include:

1) requires version control software to ensure that the code submitted by team members does not cause integration to fail. The commonly used version control software is IBM Rational ClearCase, CVS, Subversion and so on;

2) developers must submit their code to the version control repository in a timely manner, and must update the code from the version control repository regularly to the local;

3) A dedicated integration server is required to perform the integration build. Depending on the actual project, the integration build can be triggered directly by the modification of the software, or it can be started on a regular basis, such as every half hour.

4) The success of the build must be ensured. If the build fails, fixing the errors in the build process is the highest priority work. Once repaired, you need to start the build manually.

Components of a continuous integration system

Thus, a complete build system must include:

    1. An automated build process that includes automated compilation, distribution, deployment, and testing.
    2. A code repository that requires version control software to guarantee the maintainability of the Code and as a repository for the build process.
    3. A continuous Integration server. The Jenkins described in this article is a continuous integration server with simple configuration and easy to use.

About Jenkins

Jenkins is an open source project that provides an easy-to-use, continuous integration system that frees developers from complex integrations and focuses on more important business logic implementations. At the same time, Jenkins can implement errors in monitoring integration, provide detailed log files and reminders, and graphically display the trend and stability of project construction in the form of graphs. The basic features of Jenkins are described below.

Jenkins is easy to install, just download the latest Jenkins.war file from the Jenkins home page and run Java-jar Jenkins.war. You can also click the Launch button on the Jenkins page to finish downloading and running Jenkins.

Figure 1. Jenkins Launch button

After Jenkins is started, a background process runs in command-line mode. When you open http://localhost:8080 in the browser's address bar, you can see the Jenkins page. The value of Jenkins is that it has very high availability and can be easily configured from its interface, with more configuration and usage information available on the official website of Jenkins.

Figure 2. Run Jenkins Figure 3 in command line mode. Jenkins Main interface

Interestingly, Jenkins also offers a very rich plug-in support, which makes Jenkins more and more powerful. We can easily install a variety of third-party plug-ins, so as to facilitate the integration of third-party applications. Jenkins, for example, provides plug-in support for IBM Rational ClearCase.

Figure 4. Jenkins can integrate ClearCase plug-ins

In addition, Jenkins offers a wealth of management and configuration features, including system configuration, management plug-ins, viewing system information, system logs, node management, Jenkins command-line windows, information statistics, and more. Try it and you'll find Jenkins very good to use.

Figure 5. Jenkins offers a wealth of management capabilities

Back to top of page

Quickly build a continuous integration environment based on Jenkins

As described in the previous article, a continuous integration environment needs to include three elements: the code repository, the build process, and the continuous integration server. After a preliminary understanding of Jenkins, we use an example to focus on how to quickly build a simple Jenkins-based continuous integration environment.

Let's assume that the code repository we're using is IBM Rational ClearCase. Jenkins provides plug-in support for ClearCase, which makes it easy to connect to Base ClearCase or UCM ClearCase, making it a code controller for Jenkins Project. Additionally, this plugin is based on the Cleartool command, so you must install the ClearCase client program on the continuous integration server of Jenkins.

Select ClearCase Plugin in the plugin management interface of Jenkins and click the Install button at the bottom of the page.

Figure 6. Select the ClearCase plugin

After the installation is prompted in the open page, Jenkins needs to restart to activate the plugin. After re-executing Java-jar Jenkins.war, on the Jenkins page, we can see that ClearCase plugin has been installed to Jenkins.

Figure 7. ClearCase Plugin installed successfully

Similar to IBM Rational CLEARCASE,SVN (Subversion) is a popular version management tool. Many open source software uses SVN as the code version management software. In order to make the instance more representative, we use SVN as the code memory in this article.

Next, we started a new Jenkins project, and as we needed to connect SVN's code memory, we chose Build a Free-style software project.

Figure 8. New Jenkinstest Job

Then we can easily configure the Jenkinstest project. Jenkins is a very humane point is to have a help icon on the right side of each configuration item, click on this icon, Jenkins will show you how to configure this configuration item.

Figure 9. Configure Jenkinstest

Configure Source code Management based on the actual SVN server server information, which enables Jenkins to know where to get the latest code. In this example, it is assumed that Repository is local.

Figure 10. Configure connection to SVN server

Based on development needs, suppose we need to rebuild every one hours. Select Build periodically and fill in the Schedule with 0 * * * *.

The first parameter represents the minute minute, the value 0~59;

The second parameter represents the hour hour, the value 0~23;

The third parameter represents the day, value 1~31;

The fourth parameter represents the month, the value 1~12;

The last parameter represents the week week, and the value 0~7,0 and 7 are all represented in Sunday.

So 0 * * * * represents the first 0 minutes of each hour to perform a build.

Figure 11. Choose how to trigger the build

The next step is to add the build. Jenkins offers four options for us to choose from, and to execute or invoke external commands and scripts as needed.

Figure 12. Four Build step options

In this example, we compile and generate the Jar file from the Java code in SVN repository by invoking and executing the Windows batch command. You can also write your own shell script configuration here based on the actual project.

Figure 13. Configure Execute Windows Batch command

Select and configure other options, such as email reminders, and then click Save.

Figure 14. Configure Email Reminders

The Jenkinstest Job will be built in the next 0 minutes of every hour. We can observe the progress and final state of the build in Jenkins--success or failure. The sun represents a previous build without any failure, and the blue ball represents a successful build.

Figure 15. Jenkinstest Start building

At the same time we can click Jenkinstest to see the output of a single built Console. From here we can see that the first step in the build is to check out the out code from the SVN server and then invoke the Windows batch command we configured earlier.

Figure 16. Jenkinstest built-in console output

Finally, we can see the final result of build Success, which indicates that the build was successful.

Figure 17. Build a successful Console output

Next we create a new Jenkins Job to distribute the generated build to different nodes. This build triggers we choose build after the other projects is built, so that the Job is triggered after the jenkinstest successful build. This will enable our auto build and auto-distribution capabilities.

Figure 18. New Distribute Job

The difference is that this time we chose to call the Ant script to complete the work of the distribution. You only need to configure the XML file for the Ant script in Targets for Jenkins to invoke.

Figure 19. Distribute calling an external Ant script

Then we can observe the state of the build in Jenkins. Once the build fails we can see the corresponding alert icon, and if the email alert is configured, the person concerned will also receive the message. Remember that the failure to analyze and process the build is the highest priority, as we have previously warned. Next, we can also add more Jenkins projects to implement automated testing and other functions, so that continuous integration more convenient and efficient service to project development.

Figure 20. View Continuous Integration Status

Back to top of page

Conclusion

This article briefly introduces the concept of continuous integration and highlights how to quickly build a continuous integration environment based on Jenkins. Through the description of concrete examples, I believe readers have a clearer understanding and understanding of Jenkins ' basic functions and methods of realization. In fact, Jenkins's functionality is far from what is described in this article, and Jenkins also features detailed log processing and analysis of continuous integration build status. We hope to share with you in further study and application.




Finishing: http://www.ibm.com/developerworks/cn/java/j-lo-jenkins/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Quickly build a continuous integration environment based on Jenkins

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: