Use Jenkins to configure Git + Maven for automated building

Source: Internet
Author: User

Use Jenkins to configure Git + Maven for automated building
Background

I recently installed Jenkins and tried it by referring to various materials on the Internet for a long time. However, I found so many materials, with a similarity of more than 90% !!!, In the same installation process, I tested several machines, but I had to feel that my capabilities were limited. I finally found out my ideas and shared them with you, we hope that you will avoid detours during installation.

PS: I hate the kind of paste-and-copy, brainless bloggers who want to solve the problem. But the result is the same, which not only wastes everyone's time, it also wastes everyone's feelings. Therefore, I will record my problems and solutions and share them with you.

Knowledge Background

The first thing we need to understand is that Jenkins helps us compile and package the code in a unified manner, and can also be released in the tomcat container.

This means that the process of compiling, packaging, uploading, and deploying to Tomcat is handed over to Jenkins through configuration. Jenkins uses the given Code Address URL, pull the code to its "host server" (this is my personal name, which will be used below, that is, the installation location of Jenkins), compile, package, and publish it to the container.

Therefore, we can note that the Jenkins host server must have the following basic environments: Code clone (Git), code compilation (Maven), and code running (Tomcat, in other articles, install jenkins and ignore some basic configurations.

Next we will start to explain the installation process of each part. If you have installed a stage, you can proceed with this step.

1. Install Git

1. Install Dependencies

sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

Note: perl-ExtUtils-MakeMaker is also a member of these installation lists. Do not use the line breaks shown as two invocation commands.

2. Download Git

Select a directory to store the downloaded git, for example,/home/xuliugen/tmp. You can download the corresponding version from the official website as needed.

wget https://github.com/git/git/archive/v2.3.0.zip

3. Decompress git

This is the case after the download. Don't be surprised. just decompress the package directly.

Because the download is a zip file, use the command to decompress it to the git directory:

# After parameter-d, the unzip v2.3.0-d git directory is decompressed.

4. Compile and install git

Go to the git directory

Install it in the "/usr/local/git" directory. The command is as follows:

make prefix=/usr/local/git allsudo make prefix=/usr/local/git install

5. Configure Git

Sudo vim/etc/profile # edit the profile file

Then we can see that this file already has many configurations. Just add the git path at the bottom:

export PATH=/usr/local/git/bin:$PATH

Put this passage on the last side, and then use the source command to apply the modification:

source /etc/profile

6. Check whether Git is successfully installed.

git --version

2. Install Maven

1. Download and decompress Maven

Download the Maven installation package and find the appropriate version as needed. After decompression, my location is:

2. Configure Maven

Edit :~ /. Modify the bash_profile file according to the notes.

# Maven directory export M2_HOME =/home/xuliugen/software/maven/apache-maven-3.3.3 # maven bin directory export M2 = $ M2_HOME/bin # Add maven bin to the PATH variable export PATH = $ M2: $ PATH # configure the directory where JAVA_HOME is located, note that this directory should have bin folder, bin should have commands such as java export JAVA_HOME =/usr/lib/jvm/jre-1.7.0

Run: source ~ /. Modify the bash_profile Application

3. Check whether Maven is successfully installed.

Use mvn-version to view the result.

3. Deployment of Jenkins

Jenkins is easy to install. Simply put the war in the container and run it.

1. Put jenkins in Tomcat and decompress it. Start Tomcat. After the startup is successful, access the ip address and port as follows:

After the startup is successful, the above interface is displayed, indicating that the startup is successful.

2. Install the plug-in

Before configuration, because Git pulls the code, you must first install the plug-in.

Find plug-in management: use ctrl + f to search for the Deploy to container Plugin plug-in on the "optional plug-in" interface (this supports deploying code to the tomcat container)

Check and click the button below: Install directly. This may take a long time and you can wait.

After the installation is complete, if the check box is selected, jenkins will be restarted after the installation is complete.

Then install: GIT plugin. the above steps are the same. If you use the above method, the installation may fail due to network reasons, which requires us to use another method for installation.

Search for GIT plugin in "Optional ins" in the same way, find it, and click the blue Link (it is best to right-click it in a new window and place it to overwrite the jenkins Interface)

Will jump to the Git Plugin plug-in information address:

You can see that the plug-in ID is: git, and then in: http://updates.jenkins-ci.org/download/plugins/ where the search (ctrl + f) can be found, click in, select a version for download:

Click to download an hpi file.

Then, in the system management-management plug-in-Advanced Tab, you can see the upload plug-in from the drop-down list and select the file to upload the downloaded hpi file, it is automatically installed. This method can also be used to install Deploy to container Plugin.

After the installation is complete, you can see the newly installed plug-in the installed Tab:

3. Configure

On the left side of the page, click system management.

The first line of yellow information above indicates the encoding problem. You can modify it in the Tomcat-> conf-> server. xml file.

4. Jenkins system settings

Click: system settings. set all the settings that are not emphasized here as the default settings.

(1) JDK. aliases are arbitrary. Select Your jdk location. We recommend that you use sun jdk instead of openjdk For jenkins.

(2) Git Configuration

Note that the git location here is the executable file address, that is, the git directory of the executable file under git-bin (similar to the java executable file location under bin in java)

If you fill in an error, you will not be able to find git or other errors (bottom, third problem under other issues) in the future. Please note that!

Distributed building and deployment of Jenkins-nodes

(3) Ant Configuration

Since Ant is not used and configuration is not performed this time, you can set it according to the configuration.

(4) Configure Maven and select the storage location of maven.

(5) Jenkins Location

Here, the ip plus port and a path name are configured. The mailbox needs to be set. Later, the result of jenkins execution will be sent to the email.

(6) Email Notification

The QQ mailbox I configured here, you can set the corresponding smtp server according to the situation, the user name and password are their own QQ mailbox and the password, if not set, an error will be reported when jenkins builds a project in the future. The error message is well understood and found well because no email is configured.

First, make sure that the smtp and pop statuses of the email are enabled so that the verification can pass:

Click the Application below and save it.

5. Configure Global Security

Go back to system management, and click Configure Global Security. Configure the Security according to the following information.

Click Save after the application is saved. in the upper-right corner of the screen, there is a login-registration, and click Register to log on to the user.

Here, if it is the company's Intranet, or the last established jenkins is used by the company, the best user name and password is the company's account password, and the mail is also the company's mail, this facilitates subsequent operations.

Now the basic configuration of Jenkins is complete.

Create a Job

1. Create a project

After you click log on, you will see the following interface: My Views

Click in

Click: Create a new task

Select the maven project and click "OK". The Item name here needs to be used later. The configuration below also applies to this Item.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.