forked from manikcloud/elk-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
31 lines (26 loc) · 1.13 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
node {
def application = "springbootapp"
def dockerhubaccountid = "varunmanik"
def app // defining app variable here to be globally accessible
stage('Clone repository') {
checkout scm
}
stage('Build image') {
app = docker.build("${dockerhubaccountid}/${application}:${BUILD_NUMBER}")
}
stage('Push image') {
withDockerRegistry([ credentialsId: "dockerHub", url: "" ]) {
app.push()
app.push("latest")
}
}
stage('Deploy') {
sh ("docker ps -q --filter ancestor=${dockerhubaccountid}/${application} | xargs -r docker stop") // stop the existing container if it's running
sh ("docker ps -a -q --filter ancestor=${dockerhubaccountid}/${application} | xargs -r docker rm") // remove the existing container if it exists
sh ("docker run -d -p 81:8080 -v /var/log/:/var/log/ ${dockerhubaccountid}/${application}:${BUILD_NUMBER}")
}
stage('Remove old images') {
// remove docker old images
sh('docker rmi $(docker images -q ' + dockerhubaccountid + '/' + application + ' | awk \'NR>3\') -f || true')
}
}