-
Notifications
You must be signed in to change notification settings - Fork 73
/
Jenkinsfile
113 lines (103 loc) · 3.2 KB
/
Jenkinsfile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
pipeline{
agent {
label "master"
}
parameters {
string(name: "branch", defaultValue: "master", description: "Git分支")
}
environment {
docker_image = 'iweb'
docker_container = 'iWebObj'
}
stages{
stage("同步最新代码"){
steps{
sh '''
mkdir -p iWeb
'''
dir("iWeb"){
checkout(
[
$class: "GitSCM",
branches: [[name: "$params.branch"]],
extensions: [[$class: "CleanBeforeCheckout"]],
userRemoteConfigs: [[url: "git@github.com:princeqjzh/iWeb.git"]]
]
)
}
}
}
stage("编译打包"){
steps{
sh '''
cd ${WORKSPACE}/iWeb
mvn clean install -Dmaven.test.skip=true
mv target/iWeb.war target/ROOT.war
'''
}
}
stage("清理docker环境"){
steps{
script{
try{
sh 'docker stop ${docker_container}'
}catch(exc){
echo '${docker_container} container is not running!'
}
try{
sh 'docker rm ${docker_container}'
}catch(exc){
echo '${docker_container} container does not exist!'
}
try{
sh 'docker rmi ${docker_image}'
}catch(exc){
echo '${docker_image} image does not exist!'
}
}
}
}
stage("创建新docker镜像"){
steps{
script{
try{
sh '''
cd ${WORKSPACE}/iWeb
docker build -t ${docker_image} .
'''
}catch(exc){
echo 'Make ${docker_image} docker image failed, please check the environment!'
}
}
}
}
stage("启动docker容器"){
steps{
script{
try{
sh 'docker run --name ${docker_container} -d -p 8111:8080 ${docker_image}'
}catch(exc){
echo 'Start docker image failed, please check the environment!'
}
}
}
}
stage("健康接口测试"){
steps{
sh '''
cd ${WORKSPACE}/iWeb
mvn test
'''
}
}
}
post {
always {
junit (
testResults: 'iWeb/target/surefire-reports/*.xml'
, allowEmptyResults: true
)
emailext body: '$DEFAULT_CONTENT', recipientProviders: [[$class: 'RequesterRecipientProvider']], subject: '$DEFAULT_SUBJECT'
}
}
}