jenkins maven tomcat做持续集成的时候几个关键配置

jenkins maven tomcat做持续集成的时候几个关键配置

maven 采用 maven 3.0以上的版本。tomcat 采用 tomcat 7.0 以上的版本

1. tomcat 配置用户账号和权限

tomcat-users.xml

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

2. maven 配置 tomcat 账号

setting.xml 文件


<servers>
    <server>
      <id>servername</id>
      <username>admin</username>
      <password>admin</password>
    </server>
  </servers>
3. 项目 pom.xml 配置


3.1 build 配置节配置 tomcat 发布插件,注意 server 必须与2中一致,增加update 配置项,更新发布的文件,

tomcat 的发布路径为 http://serverip:port/manager/text


<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.1</version>
	<configuration>
		<url>http://192.168.0.51:8081/manager/text</url>
		<update>true</update>
		<server>servername</server>
		<username>admin</username>
		<password>admin</password>
		<path>/info</path>
	</configuration>
</plugin>
3.2 build 配置节配置部署时测试相关,忽略测试



<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.14</version>
	<configuration>
		<skipTests>true</skipTests>
	</configuration>
</plugin>
buid下所有插件例子



                <plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.5</version>
				<executions>
					<execution>
						<phase>compile</phase>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>2.4</version>
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-clean-plugin</artifactId>
				<version>2.4.1</version>
				<configuration>
					<filesets>
						<fileset>
							<directory>src/main/webapp/WEB-INF/lib</directory>
							<followSymlinks>false</followSymlinks>
						</fileset>
					</filesets>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.14</version>
				<configuration>
					<skipTests>true</skipTests>
				</configuration>
			</plugin>
			<plugin>
				<!--<groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> 
					<version>1.1</version> -->
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.1</version>
				<configuration>
					<url>http://192.168.0.51:8081/manager/text</url>
					<update>true</update>
					<server>booksair</server>
					<username>admin</username>
					<password>admin</password>
					<path>/info</path>
				</configuration>
			</plugin>
		</plugins>

4. jenkins 项目配置

jenkins mavne goal目标为(针对tomcat 7)clean install tomcat7:deploy

tomcat 配置 

WAR/EAR files:**/site.war

tomcat url: http://serverip:port/ (这里不用配置项目路径 或者 manager 路径,否则会出现 Unkown /manager/text/list 错误)

    这里只是概要说明了下集成的主要配置,如果有不完整的大家可以提出来,我补充下。


你可能感兴趣的:(maven,tomcat,Jenkins)