欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven、jenkins动态打包实现不同配置文件部署

程序员文章站 2022-06-13 20:54:35
...

参考:https://blog.csdn.net/huangchao064/article/details/73616320
https://my.oschina.net/vernon/blog/271970
因项目需要使用jenkins部署到测试、开发两个环境、但是配置文件有些差异,每次部署要先修改配置文件很麻烦,于是搜索是否有好的解决方案,尝试了一下jenkins结合maven实现配置文件动态打包
1.pom做修改

<profiles>
	<profile>
		<id>local</id>
		<properties>
			<package.environment></package.environment>
		</properties>
		<activation>
			<activeByDefault>true</activeByDefault>
		</activation>
	</profile>
	<profile>
		<id>dev</id>
		<properties>
			<package.environment>build/dev</package.environment>
		</properties>
	</profile>
	<profile>
		<id>test</id>
		<properties>
			<package.environment>build/test</package.environment>
		</properties>
	</profile>
</profiles>
		<finalName>bdf_boot</finalName>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<excludes>
					<exclude>local/*</exclude>
					<exclude>test/*</exclude>
					<exclude>dev/*</exclude>
				</excludes>
			</resource>
		</resources>
	<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.1.0</version>
				<configuration>
					<archive>
						<addMavenDescriptor>false</addMavenDescriptor>
					</archive>
					<warName>bdf_boot</warName>
					<webResources>
						<resource>
							<directory>src/main/resources/${package.environment}</directory>
							<targetPath>WEB-INF/classes</targetPath>
							<filtering>true</filtering>
						</resource>
		<!--				<resource>
							<directory>src/main/resources/public</directory>
							<targetPath>WEB-INF/classes</targetPath>
							<filtering>true</filtering>
						</resource>-->
						<!--<resource>-->
						<!--<directory>${project.build.directory}/classes</directory>-->
						<!--<includes>-->
						<!--<include>**/*.properties</include>-->
						<!--<include>**/*.xml</include>-->
						<!--</includes>-->
						<!--</resource>-->
					</webResources>
				</configuration>
			</plugin>

创建文件夹
maven、jenkins动态打包实现不同配置文件部署
jenkins修改打包参数

maven、jenkins动态打包实现不同配置文件部署
p 后面为参数
clean install -pl bdf_boot -am -amd -Pdev -Dmaven.test.skip=true