当前位置: 首页 > news >正文

Jenkins部署Maven多环境项目(dev、beta、prod)的参数设置

推荐阅读:

使用Jenkins配置Git+Maven的自动化构建


在一个多开发和生产环境的项目中,有dev、beta、prod等环境设置,如下:

这里写图片描述

pom.xml文件内容如下,指定plugins和profiles等:

 <build>
        <finalName>dlt-server</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <!--使用下边的插件可以跳过测试test中的测试-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>dev</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources.dev</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources.prod</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>beta</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources.beta</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </build>
        </profile>
        <profile>
            <id>betb</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources.betb</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </build>
        </profile>
    </profiles>

resource、resource.beat、resource.dev、resource.prod分别代表了不用环境的参数设置,我们在本地打包部署的时候,可以选择以下命令进行打包编译:

1、编译跳过测试:

mvn clean install -Dmaven.test.skip=true

2、部署到远程Nexus:

mvn deploy -Dmaven.test.skip=true

3、打包编译为不同的环境

mvn clean install -Pdev -Dmaven.test.skip=true

如果我们在使用Jenkins的时候不指定特定的参数的话,Jenkins默认只会根据resource 的环境参数进行编译打包,而对于特定环境dev、beta、prod这些环境变量并不会编译打包。

那么我们在使用Jenkins的时候如何设置这些参数,使得按着我们的想法去编译执行哪?答案如下:

Jenkins ver. 2.46.1下是这样设置的:

这里写图片描述

其中Goals and options 指定的就是以何种命令进行编译,注意的是这里是没有 ‘mvn’的,这一点在红色圈的位置也有说明,如果自己不知道加上了‘mvn’也就是参数为:

mvn clean install -Pdev -Dmaven.test.skip=true

就会报错:

这里写图片描述

[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

因此,使用正确的参数之后就可以正确的编译了~

相关文章:

  • MATLAB地图工具箱学习总结(一)从地图投影说起
  • MySQL存储引擎MyISAM与InnoDB区别总结整理
  • Atitit。数据库 安全性 重要敏感数据加密存储解决方案
  • MySQL半同步复制原理配置与介绍
  • GIT 远程仓库:添加远程库、从远程库克隆
  • 用优雅的方式重装Windows 10不可使用的应用程序
  • 使用Generic Webhook Trigger插件实现Jenkins+WebHooks(码云)持续集成
  • Redis实战和核心原理详解(4)Redis存储Key的一种设计实现方式:模式匹配
  • 第一次冲刺阶段(六)
  • MyBatis关联映射:一对一、一对多
  • xshell配色Solarized Dark
  • MySQL必知必会知识点总结一二
  • Spring Boot和Spring Cloud学习资源推荐
  • 代理模式的java实现
  • MySQL日志文件之错误日志和慢查询日志详解
  • hexo+github搭建个人博客
  • JS中 map, filter, some, every, forEach, for in, for of 用法总结
  • (十五)java多线程之并发集合ArrayBlockingQueue
  • [rust! #004] [译] Rust 的内置 Traits, 使用场景, 方式, 和原因
  •  D - 粉碎叛乱F - 其他起义
  • ECMAScript入门(七)--Module语法
  • Java新版本的开发已正式进入轨道,版本号18.3
  • Js基础知识(四) - js运行原理与机制
  • TCP拥塞控制
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 回顾2016
  • 聊聊redis的数据结构的应用
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 微信公众号开发小记——5.python微信红包
  • 在weex里面使用chart图表
  • 正则表达式
  • PostgreSQL之连接数修改
  • ​​​​​​​GitLab 之 GitLab-Runner 安装,配置与问题汇总
  • # 睡眠3秒_床上这样睡觉的人,睡眠质量多半不好
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (附源码)springboot工单管理系统 毕业设计 964158
  • (附源码)SSM环卫人员管理平台 计算机毕设36412
  • (附源码)ssm教师工作量核算统计系统 毕业设计 162307
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (四)库存超卖案例实战——优化redis分布式锁
  • (转)3D模板阴影原理
  • (转)大型网站的系统架构
  • (转)一些感悟
  • . Flume面试题
  • .dat文件写入byte类型数组_用Python从Abaqus导出txt、dat数据
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .NET CLR基本术语
  • .net core 6 集成和使用 mongodb
  • .net MVC中使用angularJs刷新页面数据列表
  • .NET/C# 的字符串暂存池
  • .net操作Excel出错解决
  • .NET开源项目介绍及资源推荐:数据持久层 (微软MVP写作)