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>
创建文件夹
jenkins修改打包参数
p 后面为参数
clean install -pl bdf_boot -am -amd -Pdev -Dmaven.test.skip=true
上一篇: 从零开发一个 Java Web 项目要点
下一篇: 揭秘:千里跃进大别山是妙笔还是败笔?