1 Introduction 1.1 Document Overview
This article mainly introduces the installation and integration of Jenkins,sonar, based on Ant,maven construction. Use an example to describe the compile-and-package deployment of Jenkins and code checking. Finally integrated with Jenkins. (At this stage is only simple integration, the subsequent need to modify Accio source to do deep integration)
1.2 Expected readers
System Configuration administrator: To know how to build a continuous integration environment, there are problems can be found;
Architect: Understand the principle of continuous integration and assist in continuous integration of project access. Projects in the continuous integration of the operation of the environment, maintenance, analysis of construction anomalies, etc.;
Maintenance Personnel: Restart Service, troubleshoot environmental issues, project access support;
1.3 About Continuous integration
Provides a set of sustainable integration project processes. Be able to provide daily build, automated test support for connected projects, improve project quality and save project cost.
2 Pre-installed software
Software name Platform notes
JDK1.7.0_17 Win7 Operating System
apache-ant-1.9.6 Win7 Ant
apache-tomcat-6.0.13 Win7 Tomcat Container
3 Installation List
Software name Platform notes
Jenkins Win7 Port 8080
sonarqube-5.1.2 Win7 Port 9000
sonar-runner-2.4 Win7
nexus-2.7.1-01 Linux maven Private Service
4 Jenkins Installation Step 4.1 Install the Jenkins service side
Download Jenkins:https://wiki.jenkins-ci.org/display/jenkins/meet+jenkins from Jenkins official website click "Download Jenkins.war"
Downloaded for Jenkins.zip to change it to Jenkins.war package, there are two ways to run it
1. Run the Java-jar Jenkins.war with the built-in jetty server.
2. Deploy the downloaded war package file to the servlet container, and then launch the container (recommended this way).
Open Http://localhost:8080/jenkins with your browser and visit the Jenkins home page.
Installation is successful!
4.2 Modifying the Jenkins workspace
Jenkins default workshop in C:\Users\xxxxxx.jenkins, modify work empty to D:\jenkins, only need to add environment variable
Jenkins_home=d:\jenkins
Restart Jenkins;
4.3 Basic configuration
Configure Java_home \ant_home\. With these three items configured, Jenkins can support the Ant-built Jave project.
Address:
Java_home=d:\program Files (x86) \java\jdk1.7.0_17
ant_home=d:\ant-1.6.5
Open http://localhost:8080/with your browser and visit the Jenkins home page.
Click on the "System Administration" page
1. UTF-8 encoding
Your container doesn ' t use UTF-8 to decode URLs. If non-ascii characters as a job name etc, this is cause problems. See Containers and Tomcat i18n for more details.
Jenkins recommends using UTF-8 encoding in tomcat to configure the Server.xml file for conf directory under Tomcat
2. System settings
On the already-running Jenkins home page, click System settings on the left to enter the following interface:
3.JDK, ant Configuration
4.Jenkins location Configuration
5. Email notification configuration
Note: If you use the QQ mailbox to open the SMTP service, opened the mailbox click "Settings" "Account"
4.4 Mail Plugin Installation
Jenkins default mail sending function is very weak, many people send, by the situation sent, mail template support is not good, so need to follow the enhanced version of the Mail plugin.
Open http://localhost:8080/with your browser and visit the Jenkins home page.
Click on "System Management"-"Management plugin"
Select the "optional plugins" card to display all the plugins that can be downloaded and installed. Select the "Email Extension Plugin" plugin and click on the button.
After the plugin installation is complete, log on to the server and restart the Jenkins service!
After the service restarts, open http://localhost:8080/with your browser and visit the Jenkins home page.
Click on "System Management"-"System settings"
See the "Extended e-mail Notification" theme hive to prove the configuration was successful.
The Email-ext plugin allows you to use variables to dynamically insert data into the subject of the message and the content. A variable is a string that starts with a $ (dollar sign) and ends with a space. When a message is triggered, all variables of the subject and content body fields are dynamically replaced by real values. Similarly, the "value" in a variable can contain other variables, and will be replaced with the actual content.
The contents of the message are as follows:
Project Name: $PROJECT _name
Build Number: $BUILD _number
SVN version number: ${svn_revision}
Build Status: $BUILD _status
Trigger Reason: ${cause}
Build Log Address: ${build_url}console
Build Address: $BUILD _url
Changeset: ${jelly_script,template= "html"}
Global properties in a detailed
1. Override Global Settings: If not selected, the plugin will use the default e-mail notification notification option. Instead, you can override it by specifying settings that are different from the (default option).
2. Default Content Type: Specifies the type of message content to send after build, with text and HTML two.
3. Use List-id Email header: Set up a List-id mail header for all messages so you can filter on the mail client. It can also block most of the email senders ' automatic replies (such as leaving the office, taking vacations, etc.). You can use any name or ID number you are accustomed to, but they must conform to one of the following formats (the real ID must be included in the < and > tags):
Build Notifications
"Build Notifications"
For more detailed List-id instructions, see RFC-2919.
4. Add ' Precedence:bulk ' Email Header: Set priority, please refer to RFC-3834 for more detailed instructions.
5. Default Recipients: Customize the default e-Mail recipient list. If not overridden by the project configuration, the plugin will use this list. You can use the $ default_recipients parameter in the project configuration to include this default list, as well as add new addresses at the project level. Add cc: cc: Email address for example, Cc:[email protected]
6. Reply to list: Reply list, A Comma separated list of e-mail addresses to use in the reply-to header of the email. This value is available as $DEFAULT _replyto in the project configuration.
7. Emergency Reroute: If this field is not empty, all e-mails will be sent separately to that address (or address list).
8. Excluded committers: To prevent mail from being considered spam by the mail system, the mailing list should not have an extended account name (such as:@domain. com), and use commas to separate
9. Default Subject: Custom email notification with the name of the subject. This option can replace some parameters in the subject field of the message so that you can include the specified output information in the build.
Maximum Attachment Size: Maximum message attachment size.
One. Default content: Custom message notification defaults to the body. This option can replace some parameters in the contents of the message so that you can include the specified output information in the build.
Default Pre-send script: Scripts to execute before sending (note: Grooy script, which I see in an article, is not necessarily accurate).
Enable debug mode: Enables debugging of the plugin. This will add additional log output, build logs, and Jenkins logs. Useful when debugging, but not for production.
Enable Security: When enabled, the ability to send scripts is disabled and goes directly to the Jenkins instance. If a user tries to access a Jenkins managed object instance, a security exception is thrown.
Content Token Reference: Variables that can be used in the message, all of which are optional.
Mail:
Detailed configuration can refer to Https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin
4.5 Permissions Plug-in installation
Click "System Management"-"Management plugin" "Optional plugin" in the search box enter "role-" point "direct Download"
Click on "System Management"-"Configure Global Security"
Click "System Management"-"Manage and Assign Roles"
Click on "Manage role", role to add new roles.
Click "Manage User" in "System Management" to add user
Click "Assign Roles", User/group to add, add the appropriate permissions to the user
Note: If you add admin permissions to Anonymous, the system does not have to login and has admin privileges, so the other role permissions are disabled.
4.6 Automatic Deployment plug-in installation
Click "System Management"-"Management plugin" "Optional plugin" search "Deploy to Container Plugin", "Direct download"
Configure Tomcat permissions, modify Tomcat-users.xml under Tomcat's Conf directory, and add content.
4.7 Building a free-style project
On the already-running Jenkins home page, click on the new job on the left to enter the following screen:
Enter project name Select JDK (JDK already configured in global configuration)
Fill in the SNV address of the project
Configure the trigger, "H/15 * * * * * * * * *" means every 15 minutes to check that SVN has no updates, updates are repackaged.
Select the Project Builder tool, which is already configured in the global configuration using ant,ant in this example.
The configuration build completes the automatic deployment, the deployment needs to install the Deploy plugin, the installation method installs with the mail plug-in. If you are deploying a cluster, you will need to click "Add Container" to add a new container to deploy.
See the following log indicating successful deployment
Configuring the Mail Plugin
Click "Save". To build the project, click "Build Now"
Click the small triangle to the right of the build date,
Click "Console Output" to view the build log
The test project is automatically built for packaging and is deployed to the remote server after packaging is complete.
5 Sonar Installation 5.1 sonar installation
Download Sonar http://www.sonarqube.org/downloads/, after downloading sonar is a ZIP package decompression can be.
After downloading, unzip the client and place a place randomly
If I put it in d:\
Enter into D:\sonarqube-5.1.2\bin here to note that choosing 32 or 64 is the JDK that corresponds to your configuration)
Create DATABASE, default database H2, here we change to MySQL
CREATE DATABASE sonar CHARACTER SET UTF8 COLLATE utf8_general_ci;
Create user
CREATE USER ' sonar ' identified by ' sonar ';
Authorization to the user
GRANT all on sonar.* to ' sonar ' @ '% ' of ' identified by ' sonar ';
GRANT all on sonar.* to ' sonar ' @ ' localhost ' identified by ' sonar ';
FLUSH privileges;
Modify the Sonar.properties file
To add the following, sonar comes with MySQL driver by default.
Sonar.jdbc.username=sonar
Sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://10.10.5.64:3306/sonar?useunicode=true&characterencoding=utf8& Rewritebatchedstatements=true
Sonar.jdbc.driverclassname=com.mysql.jdbc.driver
Run "Startsonar.bat"
With access to port 9000, sonar comes with a jetty server by default. Default User name password admin, admin. Some settings and menus can only be seen after logging in.
Install Sonar Pack, click "Configuration" "System" "Update Center" "Arailable Plugins" select "Chinese Pack", because I have installed the Chinese package, so it is not listed.
After the installation is complete, you can see the plugin in "Installed Plugins". Remember to refresh your browser after restarting
5.2 Installing Sonar-runner
Download: http://www.sonarqube.org/downloads/
Unzip after download
Modify the Sonar-runner.properties file in the Conf directory, add the following, the database
Sonar.jdbc.username=sonar
Sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://10.10.5.64:3306/sonar?useunicode=true&characterencoding=utf8& Rewritebatchedstatements=true
Sonar.jdbc.driverclassname=com.mysql.jdbc.driver
Configure environment variables, add D:\sonar-runner-2.4\bin to Path
Add files at the root of the project Sonar-project.properties
The file contents are as follows
Sonar.projectkey=hotelmonitor
Sonar.projectname=hotelmonitor
sonar.projectversion=1.2
Sonar.sources=src
Sonar.sourceencoding=utf-8
Sonar.language=java
Enter "Sonar-runner" in the project for CMD switching in start run
See the following log indicating that the code validation was successful
Login http://localhost:9000/View Code scan results
Click on the project name to view verification details
6 Jenkins and sonar integrated 6.1 Jenkins configuration
Click on "System Management" "System settings"
There are two ways of configuring Sonar-runner
The first Jenkins Auto-install Sonar-runner
The second use of an existing installation
6.2 Sonar Configuration
Click "Save".
Configuring sonar Code analysis in a project
Click on the project name to enter the project configuration, select "New Build Step", select "Invoke Standalone Sonar Analysis"
Configure as follows
Click "Save"
Commit the sonar-runner.properties under the project root to SVN,
Perform "Build Now"
See Jenkins Console output The following log, verify success
Visit http://localhost:9000/dashboard/index/HotelMonitor
View the validation results.
If Sonar-runner is installed locally, you can run the Sonar-runner in the same way as the local bat script, as long as you have to add the Sonar-runner to the environment variable, select "Add Build Step"
Enter the bat script
Modify the sonar configuration, make the following configuration, open the Sonar configuration page, configure "Disable the SCM Sensor" to "yes"
Otherwise the following error will be reported
7 maven installation and MAVEN Setup 7.1 maven installation
Download maven on MAVEN's website
http://maven.apache.org/download.cgi
Download Apache-maven-3.1.1-bin.zip and Unzip
Configuring Environment variables
Open CMD window data mvn–v view MAVEN version, print as follows to indicate successful installation.
7.2 Maven Nexus Installation
Download Nexus http://www.sonatype.org/nexus/go/, I downloaded the Linux version.
Nexus-latest-bundle.tar.gz
Copy the installation package to the machine that needs to be installed, I installed in the/opt/soft/nexus
TAR–ZXVF nexus-latest-bundle.tar.gz
Two directories will appear after decompression
CD Nexus-2.7.7-01/bin
./nexus
The output is as follows:
Lists the various commands of the Nexus
./nexus Start Service
Then in the native access Http://localhost:8081/nexus, the default user name password: admin,admin123
If the remote machine access also needs to open 8081 port, the operation is as follows:
/sbin/iptables-i input-p TCP--dport 8081-j ACCEPT #开启8081端口
/etc/rc.d/init.d/iptables Save #保存配置
/etc/rc.d/init.d/iptables Restart #重启服务
See if the port is open
/etc/init.d/iptables status
7.3 Nexus Configuration
Hosted type of warehouse, internal project release warehouse
Release repository for the release module in the releases internal module
Snapshots Release the warehouse of the internal snapshot module
3rd The third party relies on the warehouse, this data is usually downloaded by the internal personnel after the release
Proxy type of warehouse, from the remote central warehouse to find the Data Warehouse
A warehouse of group type that is used by the warehouse to facilitate the setup of our developers.
Click "Repositories" "Central" "Configuration"
Set "Download Remote Indexes" to True
Set "Remote Storage location" as: http://repo1.maven.org/maven2/
After the configuration is finished saving, right-click "Repair Index" in "Central" to download the index
View the downloaded index in "Browse index"
Note: If you do not download to the index may be because the Nexus installed directory under the Sonatype-work directory does not have permission to modify, to assign permissions to the folder;
Chmod 777–r Sonatype-work
Modify the Settings.xml file under the MAVEN installation directory Conf to add the following code
1. Add under the Profiles node
Nexus
Nexus
http://10.10.152.174:8081/nexus/content/groups/public/
True
True
Add under the Settings node
Central
</activeProfiles>
Under the Services node, add
Releases
Admin
Admin123
Snapshots
Admin
Admin123
Add in the project's Pom file
<Distributionmanagement><Repository><Id>releases</Id><Name>nexus Release Repository</Name> < url>http://10.10.152.174:8081/nexus/content/repositories/releases/ </ url> </ repository> < snapshotrepository> < id>snapshots </ id> < name>nexus Snapshot Reposito Ry </ name> < url>http:// 10.10.152.174:8081/nexus/content/repositories/snapshots/ </ url> </ snapshotrepository> </ distributionmanagement>
Then execute the clean deploy
or enter command execution in eclipse
View the jar package for a deployed deployment
7.4 Nexus upload jar Package
Right button "3rd party"
View uploaded jar packages in the index
If you want to reference the jar package simply add the XML in the description to the OPM file referenced by the project
7.5 Maven Related commands
Help:system can print all the available environment variables and Java System Properties.
Help:effective-pom is used to view the POM content that is currently in effect, meaning that the XML after all parent POM (including Super POM) is merged, so it can be used to detect whether a configuration in the Pom is in effect
Help:effective-settings can be used to view the contents of the Settings.xml file currently in effect, so it can be used to determine if a settings configuration is in effect
MVN Help:describe If you can't remember the goal of a plugin, and if you're upset because you can't think of a certain goal parameter, try this command, it'll tell you everything. Parameters: 1.-dplugin=pluginname 2. -dgoal (or-dmojo) =goalname: Used with-dplugin, it will list the goal information of a plug-in, if not enough detailed, also can add-ddetail. (Note: A plugin goal is also considered to be a "Mojo") below everyone runs MVN help:describe-dplugin=help-dmojo=describe feel it!
MVN archetype:generate How did you create your MAVEN project? Like this: MVN archetype:create-darchetypeartifactid= Maven-archetype-quickstart-dgroupid=com.ryanote-dartifact=common, if you use again, then you are out, modern people use MVN archetype:generate, It will create a project this boring thing more humane, you no longer need to remember so many archetypeartifactid, you just input archetype:generate, the rest is to do "choice".
MVN Tomcat:run with Maven, you no longer need to run the Web project with Tomcat in Eclipse (you'll often find that it's a different step in the actual job), just run mvn tomat in the corresponding directory (like/ryanote): Run command, and then you will be able to view it in the browser running Http://localhost:8080/ryanote. If you want more customization, you can configure it under the Pom.xml file in Riga: Org.codehaus.mojo 05 Tomcat-maven-plugin 07/web 08 9090 09 10 11 12 Of course you can also add parameters in the command to achieve a specific function, the following several more commonly used: 1. Skip test:-dmaven.test.skip (=true) 2. Specify port:-dmaven.tomcat.port=9090 3. Ignore test failure:-dmaven.test.failure.ignore=true Of course, if your other affiliate projects have been updated, be sure to run MVN clean install under the project root to perform the update, and then run MVN Tomcat: Run causes the changes to take effect.
Mvndebug tomcat:run This command is mainly used for remote testing, it will listen to the remote test port 8000, after opening the remote test in eclipse, it will run up, set breakpoints, debugging, everything is so simple. The parameters mentioned above apply here as well.
MVN dependency:sources so Name think righteousness, with it, you do not have to find the source code, run, your project depends on the jar package of source code will have
8 Jenkins,maven,sonar Integration 8.1 integrates
Default Jenkins has the MAVEN plugin installed
Add a Jenkins configuration to the Jenkins system administration system settings, or use the Auto install
Create a new MAVEN project and enter the SVN address in project configuration
Add sonar code Analysis and select "Sonar" after "Add Build Action Step"
After clicking "Save" to build the project, you can see Jenkins download the dependent jar package from the
Visit http://localhost:9000/to view the code monitoring report generated by sonar
Continuous Integration Jenkins+sonarqube Deployment Tutorial