forked from Rootbie/helloworld_docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
52 lines (41 loc) · 1.38 KB
/
Copy pathJenkinsfile
File metadata and controls
52 lines (41 loc) · 1.38 KB
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
node{
stage('1. Scm checkout'){
def gitCmd = 'git clone https://github.com/Rootbie/helloworld.git'
sshagent(['instanceForDocker']) {
// Remove existing git project
sh "ssh ubuntu@172.31.225.27 rm -rf helloworld "
// Clone a new git prj
sh "ssh ubuntu@172.31.225.27 ${gitCmd} "
}
}
stage('2. Maven build'){
def mvnPackage = 'mvn clean package -f helloworld/pom.xml'
sshagent(['instanceForDocker']) {
sh "ssh ubuntu@172.31.225.27 ${mvnPackage}"
}
}
stage('3. Build docker image'){
def dockerBuild = 'docker build -t trinh00thien/helloworld:v3 helloworld '
sshagent(['instanceForDocker']) {
sh "ssh ubuntu@172.31.225.27 ${dockerBuild}"
}
}
stage('4. Remove container'){
def dockerRm = 'docker rm -f web-hello'
sshagent(['instanceForDocker']) {
sh "ssh ubuntu@172.31.225.27 ${dockerRm}"
}
}
stage('5. Deploy docker image to Tomcat server'){
def dockerRun = 'docker run -p 23456:8080 -d --name web-hello trinh00thien/helloworld:v3 '
sshagent(['instanceForDocker']) {
sh "ssh ubuntu@172.31.225.27 ${dockerRun}"
}
}
stage('6. Upload Docker image to Docker Hub') {
def dockerPush = 'docker image push trinh00thien/helloworld:v3'
sshagent(['instanceForDocker']) {
sh "ssh ubuntu@172.31.225.27 ${dockerPush}"
}
}
}