-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
57 lines (50 loc) · 1.33 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
pipeline {
agent any
stages {
stage('Git') {
steps {
git branch: params.branch, credentialsId: params.credId, url: params.GitUrl
}
}
stage('写入配置') {
steps {
sh '''
''' + params.WriteFile + '''
'''
}
}
stage('构建镜像') {
steps {
sh '''
docker build -t ${origin_repo}/account/${repo}:${image_tag} .
'''
}
}
stage('停止旧容器') {
steps {
sh '''
last_cid=$(docker ps | grep ${repo}-${image_tag} | awk '{print $1}')
if [[ -n $last_cid ]]
then
docker stop $last_cid
docker rm $last_cid
fi
'''
}
}
stage('启动容器') {
steps {
sh '''
docker run -d -p ${out_ip}:${in_ip} --name ${repo}-${image_tag} ${origin_repo}/account/${repo}:${image_tag}
'''
}
}
stage('清理镜像 ') {
steps {
sh '''
docker system prune -f
'''
}
}
}
}