Jenkins and MAVEN automation build Java programs

Source: Internet
Author: User
Tags sonatype

A. Package:

1. Download Apache-maven-2.2.1-bin.tar
Http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.tar.gz
2. Download jenkins:http://mirrors.jenkins-ci.org/war/lists all release versions of Jenkins, please select download

Two. Installation

This article assumes that the operation user is Gistech.

1. Install the JDK and refer to "Installing JDK1.6 in the CentOS system".
2. Install TOMCAT7, refer to "Installing TOMCAT7 in Cenos system".

Modifying the Tomcat configuration file

$ vi/home/gistech/tomcat/conf/server.xml

Modify the connector node of port 8080 to add the following configuration

Uriencoding= "UTF-8"

3. Install Maven
1) Unzip

$ TAR-ZVXF apache-maven-2.2.1-bin.tar.gz

2) move to a different directory

$ MV Apache-maven-2.2.1/home/gistech/maven

3) Configure Environment variables
Edit. bash_profile file

$ cd/home/gistech$ Vi. Bash_profile

Add the following content

Maven_home= $HOME/mavenpath= $PATH: $HOME/bin: $MAVEN _home/binexport maven_homeexport PATH

Make environment variables effective

$ source. bash_profile

4) Verify that the installation is successful

$ mvn-v   

5) Configure Maven
Editing a MAVEN configuration file

$ cd maven/conf$ VI settings.xml

An example of modifying a configuration file is as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><settings xmlns= "http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "http://maven.apache.org/SETTINGS/1.0.0/HTTP//    Maven.apache.org/xsd/settings-1.0.0.xsd "> <localRepository>/home/gistech/~m2</localRepository> <servers> <server> <username>admin</username> <password>passwor d</password> </server> </servers> <mirrors> <mirror> <!-- This sends everything else to/public-<id>nexus</id> <mirrorof>central</ Mirrorof> <url>http://192.168.120.247:8081/nexus/content/repositories/public</url> </m            irror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in CENtral repo to direct-<!--all requests to nexus via the mirror--<repositories> <repository> <id>central</id> &LT;URL&GT;HTTP://19                        2.168.120.247:8081/nexus/content/repositories/public</url> <releases>                    <enabled>true</enabled> <updatePolicy>always</updatePolicy>                        </releases> <snapshots> <enabled>true</enabled>                <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginreposi Tory> <id>central</id> <url>http://192.168.120.247:8081/nexus/c Ontent/repositories/publIc</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <sna Pshots> <enabled>true</enabled> <updatepolicy>always&lt ;/updatepolicy> </snapshots> </pluginRepository> </pluginre positories> </profile> </profiles> <activeProfiles> <!--make the profile acti ve all the time--<activeProfile>nexus</activeProfile> </activeProfiles> <plugingro Ups> <!--define the Sonatype plugin group, so the Nexus plugins would work without typing the GRO Upid-<pluginGroup>org.sonatype.plugins</pluginGroup> </pluginGroups></settings>

Where the Localrepository node represents the stored path of the jar package that is downloaded in the virtual bus, modified according to the actual path stored.
Address included in all URL nodes: Http://192.168.120.247:8081/nexus/content/repositories/public, which represents the address of the Nexus, please modify it according to the actual address.
The username, password node indicates the username and password of the login nexus.
4. Install Jenkins
1) Copy to Tomcat WebApps directory

$ MV Jenkins.war/home/gistech/tomcat/webapps

2) Configure Environment variables
Edit. bash_profile file
Add the following content

Jenkins_home= $HOME/tomcat/webapps/jenkinsexport Jenkins_home

Make environment variables effective

source. bash_profile

3) Start Tomcat and use Http://localhost:8080/jenkins to access Jenkins

III. Basic configuration of Jenkins

1. Global configuration

Click "System Management" on the left of the home page to go to "system settings", where Jenkins is set globally
1) JDK installation. If you do not read out the system variables, set the alias and Java_home manually.
2) Maven similarly

3) Configure Administrator email notifications
Configuration methods such as:

After the configuration is complete, you can click the "test configuration by sending test Mail" button to test.
2. Create Job
1) on the page, click "New Job", enter the task name, select "Build a MAVEN2/3 project", such as:

2) Click the OK button to enter the task configuration page, first configure the project's SVN address, such as:

3) To configure MAVEN's Pom file location, you can use a relative path (relative to the location in the SVN address library), such as:

4) Configure the MAVEN compilation parameters as shown in do not perform unit tests:

For MAVEN's compilation parameters, refer to MAVEN basic commands
3. Email notification
Build a mail notification configuration for example, add the email address that you want to send an email notification to in the Recipients column.

4. Timed Construction
Build triggers allow you to configure the build time, and if you need a timed build, you can choose build periodically, which is explained in the schedule parameters:

    • 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.

The 0 * * * * indicates that the build is performed in the first 0 minutes of each hour.

5, Version update build
Many situations require Jenkins to periodically poll the repository, and as long as a version update triggers the build, Jenkins provides poll SCM support for version update builds, such as configuration parameters like timed build parameters, such as */5 * * * * for polling every 5 minutes to check if the repository is updated.

Jenkins and MAVEN automation build Java programs

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.