结合jenkins, 使用maven-assembly-plugin实现静态资源自动化部署,mave

关于jenkins的使用及自动化配置步骤,在本博上篇已经有所介绍,这里只列下如何使用maven的强大插件assembly

1、假设静态资源的目录结构为:
            static/js/xxxx
            static/css/xxxx
            static/images/xxxx

            static/configure/xxx.js
            static/pom.xml
            static/assembly.xml

2、配置pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.test</groupId>
	<artifactId>static</artifactId>
	<packaging>pom</packaging>
	<version>1.0</version>

	<properties>
		<fileName>static</fileName>
		<SettingJs>configure/xxx.js</SettingJs>
	</properties>

	<build>
		<finalName>${fileName}</finalName>

		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.6</version>
				<executions>
					<execution>
						<id>compile</id>
						<phase>compile</phase>
						<configuration>
							<target>
								<copy file="${SettingJs}" tofile="js/xxx.js"
									  overwrite="true"/>
							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.2.1</version>
				<configuration>
					<descriptors>
						<descriptor>assembly.xml</descriptor>
					</descriptors>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>



3、配置assembly.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
		  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

	<id>all</id>

	<formats>
		<format>zip</format>
	</formats>

	<fileSets>
		<fileSet>
			<directory>js</directory>
			<useDefaultExcludes>true</useDefaultExcludes>
		</fileSet>
		<fileSet>
			<directory>images</directory>
			<useDefaultExcludes>true</useDefaultExcludes>
		</fileSet>
		<fileSet>
			<directory>css</directory>
			<useDefaultExcludes>true</useDefaultExcludes>
		</fileSet>
	</fileSets>
</assembly>



4、jenkins中,当构建任务结束后,将生成static-all.zip文件,配置自动上传至目标服务器,最后使用命令unzip -o static-all.zip解压覆盖即可

转载于:https://my.oschina.net/boltwu/blog/466506

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值