-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
59 lines (59 loc) · 1.84 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
pipeline {
agent any
triggers {
pollSCM "* * * * *"
}
stages {
stage('Build Application') {
steps {
echo '=== Building Petclinic Application ==='
sh 'mvn -B -DskipTests clean package'
}
}
stage('Test Application') {
steps {
echo '=== Testing Petclinic Application ==='
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Build Docker Image') {
when {
branch 'master'
}
steps {
echo '=== Building Petclinic Docker Image ==='
script {
app = docker.build("ibuchh/petclinic-spinnaker-jenkins")
}
}
}
stage('Push Docker Image') {
when {
branch 'master'
}
steps {
echo '=== Pushing Petclinic Docker Image ==='
script {
GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true)
SHORT_COMMIT = "${GIT_COMMIT_HASH[0..7]}"
docker.withRegistry('https://registry.hub.docker.com', 'dockerHubCredentials') {
app.push("$SHORT_COMMIT")
app.push("latest")
}
}
}
}
stage('Remove local images') {
steps {
echo '=== Delete the local docker images ==='
sh("docker rmi -f ibuchh/petclinic-spinnaker-jenkins:latest || :")
sh("docker rmi -f ibuchh/petclinic-spinnaker-jenkins:$SHORT_COMMIT || :")
}
}
}
}