forked from spring-projects/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
89 lines (82 loc) · 2.33 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pipeline {
agent any
tools {
jfrog 'jfrog-cli'
jdk 'JDK17'
}
environment {
DOCKER_PATH = "/usr/local/bin"
DOCKER_IMAGE = "spring-petclinic:latest"
ARTIFACTORY_URL = "hesterinc.jfrog.io/petclinic-docker/"
PATH = "${env.PATH}:${DOCKER_PATH}"
}
stages {
stage('Checkout') {
steps {
checkout scmGit(branches: [[name: '*/main']],
extensions: [],
userRemoteConfigs: [[url: 'https://github.com/hesterch/spring-petclinic.git']])
}
}
stage('Build') {
steps {
script {
// check java ver
sh 'java -version'
// Clean and compile the project
sh './mvnw clean compile'
}
}
}
stage('Test') {
steps {
script {
// Run tests
sh './mvnw test'
}
}
}
stage('Package') {
steps {
script {
// Package the project
sh './mvnw package'
}
}
}
stage('Build Docker Image') {
steps {
script {
// check docker cli and path, for debug
// sh 'docker --version'
// Build the Docker image
sh 'docker build -t ${ARTIFACTORY_URL}${DOCKER_IMAGE} .'
}
}
}
stage('Push Docker Image to Artifactory') {
steps {
// Scan Docker image for vulnerabilities will use XRay
jf 'docker scan ${ARTIFACTORY_URL}$DOCKER_IMAGE'
// Push image to Artifactory
jf 'docker push ${ARTIFACTORY_URL}${DOCKER_IMAGE}'
}
}
stage('Publish build info') {
steps {
jf 'rt build-publish'
}
}
}
post {
always {
cleanWs()
}
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}