1. 程式人生 > >jenkins 整合maven,svn(配置鉤子程式實現提交程式碼自動構建),tomcat實現熱部署(windows+linux分別實現)

jenkins 整合maven,svn(配置鉤子程式實現提交程式碼自動構建),tomcat實現熱部署(windows+linux分別實現)

1 準備工作:

(1)執行jenkins的tomcat

(2)執行我們專案的tomcat

(3)SVN伺服器

jenkins就是一個war包,相信大家都非常熟悉,扔在tomcat  webapp下就能跑,具體操作步驟上網去搜一搜一大把,我們主要是來記錄一下如何實現鉤子程式,實現程式碼的動態部署。

jenkins配置的話我們需要配置jdk,maven,maven的settings.xml,伺服器的tomcat。

jenkins第一次進入後臺會提示去下載外掛,我們只要耐心等待一會兒就好,因為我們要實現熱部署,所以需要另外手動去下載一個叫depoly to container 的外掛, 直接ctrl+f全域性搜尋就行。

 

 

其餘配置如下:過程太簡單直接略過

 

 

 

maven 專案打包方法

 

 

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  
this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <tomcat-users> <!-- NOTE: By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. It is strongly recommended that you do NOT use one of the users in the commented out section below since they are intended for use with the examples web application. --> <!-- NOTE: The sample user and role entries below are intended for use with the examples web application. They are wrapped in a comment and thus are ignored when reading this file. If you wish to configure these users for use with the examples web application, do not forget to remove the <!.. ..> that surrounds them. You will also need to set the passwords to something appropriate. --> <!-- <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="<must-be-changed>" roles="tomcat"/> <user username="both" password="<must-be-changed>" roles="tomcat,role1"/> <user username="role1" password="<must-be-changed>" roles="role1"/> --> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="tomcat_user" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status" /> </tomcat-users>

 

 

這樣我們的專案就自動部署到伺服器的tomcat上面了,接下來就該如何自動觸發鉤子程式,去實現自動構建了。

我們進入svn伺服器根目錄:

@echo off
start cmd /c "curl -X post -v -u admin:你的jenkins登入密碼 http://127.0.0.1:8080/jenkins/view/all/job/mavent/build?token=TOUCH_TOKEN"

windows 上想要使用curl命令需要下載curl外掛,然後配置環境變數後才能起作用。

最後我們修改svn的登入許可權

 

那麼現在只要在本地電腦提交程式碼到svn伺服器,即會自動觸發構建了!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.2  自動化部署

 

自動化的具體體現:向版本庫提交新的程式碼後,應用伺服器上自動部署,使用者或測試人員使用的馬上就是最新的應用程式。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4

 

更多 Java –大資料前端 –python 人工智慧資料下載,可訪問百度:尚矽谷官網


JavaEE 高階課程系列

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

搭建上述持續整合環境可以把整個構建、部署過程自動化,很大程度上減輕工作量。對於程式設計師的日常開發來說不會造成任何額外負擔——自己把程式碼提交上去之後,伺服器上執行的馬上就是最新版本——一切都發生在無形中。

 

下面我們講帶領大家一步一步搭建整套持續整合環境,這個操作過程只需要細心認真即可,沒有任何難度。但是需要優秀的你具備以下前置知識:

 

ü  Linux 基本操作命令和 VIM 編輯器使用

 

ü  Maven 的專案構建管理

 

ü  GitHub SVN 使用