Jenkins中新建一个项目名叫web_demo_freestyle

image-20200715225156708

然后拉取代码

image-20200715225600914

然后编译打包

1
2
3
echo "——编译打包开始——"
mvn clean package
echo "——编译打包结束——"

image-20200715225756510

完成

image-20200715225906317

安装Deploy to container插件

image-20200715230043462

安装完成

image-20200716091126818

回到web_demo_freestyle项目的配置

增加构建后操作步骤->点击Deploy war/ear to a container

image-20200716181631460

输入war包目录

1
target/*.war

添加一个凭据

image-20200716181955128

输入用户名tomcat和密码tomcat

image-20200716182047299

输入tomcat服务器地址,保存

image-20200716182217356

然后构建,成功后就是这样了

image-20200716192014886

我们发现已经能访问了

image-20200716195807389

我们更改一下代码

image-20200716201356219

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();
// console.log(d)
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

image-20200716201522005

然后回到jenkins进行构建

image-20200716202150571

成功后刷新我们的tomcat

image-20200716202215931

可以看到我们的更改