Tuesday, May 10, 2016

jekins+tomcat7+maven+auto deploy+junit+svn developer log

1. what
 i need used maven to auto deploy my spring war to tomcat with version war. it can auto run junit,if ok, then publish it to tomcat,else email me error history.

2. how 2.1 install tomcat 7+

edit tomcat\conf\tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin-gui"/>
<user password="tomcat" roles="manager-gui,admin-gui" username="tomcat"/>
<user password="123456" roles="manager-script" username="admin"/>

2.2. edit spring web project's pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.pkrss</groupId>
  <artifactId>test1</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>test1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  
  <properties>
<project.sourceEncoding>UTF-8</project.sourceEncoding>

<tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>

<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>

  <dependencies>
    <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
  </dependencies>
  
  
  <build>
    <finalName>${project.artifactId}</finalName>
    
  
<directory>target</directory>
       <sourceDirectory>src/main</sourceDirectory>
       <testSourceDirectory>src/test</testSourceDirectory>
       <outputDirectory>target/classes</outputDirectory>
       <resources>
           <resource>
               <directory>src/main/resources</directory>
               <includes> 
<include>**/*</include> 
</includes>
           </resource>
       </resources>
  </build>
  
    
  <profiles>
        <profile>  
            <id>ldl</id> 
            <build> 
                <plugins>  
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7-maven-plugin.version}</version>
<configuration>  
                            <url>http://127.0.0.1:8080/manager/text</url>  
                            <path>/${project.artifactId}##${maven.build.timestamp}</path>
                            <username>admin</username>  
        <password>123456</password>
                        </configuration>  
</plugin>
                </plugins>
            </build>  
        </profile>
    </profiles>

</project>

2.3. install jekins in tomcat
used sve SCM
Poll SCM: H/5 * * * *
Build: mvn clean test tomcat7:redeploy -P ldl
Publish JUnit test result report: **/target/surefire-reports/*.xml

E-mail Notification
Recipients:  120449427@qq.com

Saved


2.4 ok