-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
45 lines (40 loc) · 1.21 KB
/
Jenkinsfile
File metadata and controls
45 lines (40 loc) · 1.21 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
pipeline {
agent any
environment {
GIT_COMMIT_ID = "${sh(returnStdout: true, script: 'git log --format="%H" -n 1 | cut -c -12')}"
}
stages {
stage('Build Java') {
steps {
slackSend message: "${JOB_NAME}: Starting build"
sh './mvnw clean verify'
}
}
stage('Build Docker image') {
steps {
sh "docker build . -f src/main/docker/Dockerfile -t oltruong/bookstore:$GIT_COMMIT_ID"
sh "docker run -d -p 80:8080 --name testjenkins oltruong/bookstore:$GIT_COMMIT_ID"
slackSend message: "${BUILD_URL}: Can you check http://localhost/bookstore?"
}
}
stage('Push Docker image') {
input {
message "Can you check http://localhost/bookstore?"
ok "All good"
}
steps {
slackSend message: "${JOB_NAME}: Pushing docker image"
echo "Pushing image"
sh "docker push oltruong/bookstore:$GIT_COMMIT_ID"
sh "docker build . -f src/main/docker/Dockerfile -t oltruong/bookstore:latest"
sh "docker push oltruong/bookstore:latest"
}
}
}
post {
always {
echo "Clean docker container"
sh "docker stop testjenkins || true && docker rm testjenkins || true"
}
}
}