-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathJenkinsfile
68 lines (60 loc) · 2.45 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
def getServer(ip){
def remote = [:]
remote.name = "server-${ip}"
remote.host = ip
remote.port = 22
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'df2d4f43-743c-417b-b730-54c9649e39b4', passwordVariable: 'password', usernameVariable: 'userName')]) {
remote.user = "${userName}"
remote.password = "${password}"
}
return remote
}
def sendFile(sshServer, file) {
sshPut remote: sshServer, from: file.form, into: file.into
}
def runDockerCompose(sshServer){
sshCommand remote: sshServer, command: "cd /root/"
sshCommand remote: sshServer, command: "docker-compose stop"
sshCommand remote: sshServer, command: "docker-compose rm -f"
sshCommand remote: sshServer, command: "docker rmi 192.168.170.210:5000/contact-center"
sshCommand remote: sshServer, command: "docker-compose up -d"
}
node{
stage('拉取代码'){
git branch: 'develop', credentialsId: 'b51a1de4-2aa4-4c16-b70f-5305cf4d789c', url: 'http://10.100.0.107/kefuSys/webim.git'
// checkout scm
}
stage('gradle 构建') {
// build and test
sh 'chmod +x ./gradlew'
sh './gradlew contact-center:bootJar'
}
stage("复制文件") {
def sshServer = getServer("192.168.170.210")
sshCommand remote: sshServer, command: "cp /data/server/jenkins/workspace/webim-218/contact-center/docker/dev/Dockerfile /data/server/jenkins/workspace/webim-218/contact-center/Dockerfile"
}
stage("构建镜像") {
// working with docker-ce
withDockerServer([uri: 'tcp://192.168.170.210:2375']) {
def customImage = docker.build("contact-center:latest", "contact-center")
}
}
stage("pull docker image") {
def sshServer = getServer("192.168.170.210")
sshCommand remote: sshServer, command: "docker tag contact-center:latest localhost:5000/contact-center:latest"
sshCommand remote: sshServer, command: "docker push localhost:5000/contact-center:latest"
sshCommand remote: sshServer, command: "docker rmi contact-center:latest"
}
stage("send docker-compose file") {
def file = [:]
file.form = 'docker/docker-compose.yml'
file.into = 'docker-compose.yml'
def sshServer = getServer("192.168.101.218")
sendFile(sshServer, file)
}
stage("run docker-compose") {
def sshServer = getServer("192.168.101.218")
runDockerCompose(sshServer)
}
}