前提
- 已经部署好Jenkins,使用版本Jenkins ver.2.46.3
- git上有相应的待自动化构建的工程
- 在服务器上的目标目录中创建了初始化的文件,其中包括部署脚本,配置等等
Jenkins
- 登录Jenkins。
- 在页面上点击“新建”。
- 填写item名称,选择maven项目,点击ok,页面自动跳转到配置界面。
- 从上到下依次:
(1)General
填写描述
(2)源码管理
选择Git
按实际情况填写Responsitory URL,比如git@xx.xx.xx.xx:JAVAWEB/ProjectName.git
选择可用的Credentials
修改branch specifier,比如*/dev
(3)构建触发器
勾除build whenever a SNAPSHOTdependency is build
勾选build when a change is pushed to Git...
(4)构建环境
无
(5)Pre Steps
无
(6)Build
Root POM: pom.xml
Goals and options: clean package
(7)Post Steps
选择Run only if build succeeds
点击add post-build step选择Execute Windows batch command
填入deploy.bat
(deploy.bat需要在工程中配置好)
(8)构建设置
勾选E-mail Notification,填写要通知的用户邮箱,用于通知构建异常
(9)构建后操作
无
- 点击Apply,点击保存
Git
配置好之后,发现提交代码并没有触发自动化构建
需要在git的配置中添加一个web hooks
其中填写的url与Jenkins中的构建触发器中的
Build when a change is pushed to GitLab. GitLab CI Service URL:
http://xx.xx.xx.xx:xxxx/project/projectName
的URL保持一致