到Jenkins
中新建一个项目名叫web_demo_freestyle
然后拉取代码
然后编译打包
1 2 3
| echo "——编译打包开始——" mvn clean package echo "——编译打包结束——"
|
完成
安装Deploy to container
插件
安装完成
回到web_demo_freestyle
项目的配置
增加构建后操作步骤->
点击Deploy war/ear to a container
输入war
包目录
添加一个凭据
输入用户名tomcat
和密码tomcat
输入tomcat
服务器地址,保存
然后构建,成功后就是这样了
我们发现已经能访问了
我们更改一下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE html> <html> <body> <h2>Hello jenkins!</h2> <div class="yesMyTime"> 当前时间: <span id="date"></span> <span id="time"></span> </div> <script type="application/javascript"> window.onload = function () { setTime(); };
function getTime() { let week = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; let localToday = ""; let d = new Date(); localToday = d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日"; let time = ""; let hh = d.getHours(); let mm = d.getMinutes(); let ss = d.getSeconds(); if (hh < 10) time += "0"; time += hh + ":"; if (mm < 10) time += "0"; time += mm + ":"; if (ss < 10) time += "0"; time += ss; return { 0: localToday, 1: week[d.getDay()], 2: time }; }
let timer = null;
function setTime() { if (timer !== null) { clearTimeout(timer); } setTimeout(function () { document.getElementById("date").innerHTML=getTime()[0]; document.getElementById("time").innerHTML=getTime()[1] + " " + getTime()[2]; setTime(); }, 1000); } </script>
</body> </html>
|
然后push
然后回到jenkins进行构建
成功后刷新我们的tomcat
可以看到我们的更改