-
Notifications
You must be signed in to change notification settings - Fork 29k
Expand file tree
/
Copy pathJenkinsfile
More file actions
77 lines (67 loc) · 2.3 KB
/
Jenkinsfile
File metadata and controls
77 lines (67 loc) · 2.3 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
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
pipeline {
agent any
environment {
DOCKER_HUB_USER = "lokokun290"
DOCKER_IMAGE = "spring-petclinic-bar"
JFROG_DOMAIN = "bardpetclinic"
JFROG_REPO = "libs-release-local"
}
stages {
stage('Compile') {
steps {
echo 'Compiling the code'
sh './mvnw compile'
}
}
stage('Test') {
steps {
echo 'Running unit tests'
sh './mvnw test'
}
}
stage('Package') {
steps {
echo 'Packaging project to JAR'
sh './mvnw package -DskipTests'
}
}
stage('Artifact to JFrog') {
steps {
script {
echo 'Uploading JAR to JFrog Artifactory'
withCredentials([usernamePassword(credentialsId: 'jfrog-creds', passwordVariable: 'JF_PASS', usernameVariable: 'JF_USER')]) {
sh """
curl -u ${JF_USER}:${JF_PASS} -X PUT "https://${JFROG_DOMAIN}.jfrog.io/artifactory/${JFROG_REPO}/spring-petclinic-${env.BUILD_ID}.jar" -T target/*.jar
"""
}
}
}
}
stage('Build Docker Image') {
steps {
echo 'Building Docker image'
sh "docker build -t ${DOCKER_IMAGE}:${env.BUILD_ID} ."
sh "docker tag ${DOCKER_IMAGE}:${env.BUILD_ID} ${DOCKER_HUB_USER}/${DOCKER_IMAGE}:latest"
}
}
stage('Push to Docker Hub') {
steps {
script {
echo 'Pushing image to Docker Hub'
withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}"
sh "docker push ${DOCKER_HUB_USER}/${DOCKER_IMAGE}:latest"
}
}
}
}
}
post {
success {
echo 'Pipeline completed successfully! Artifact is in JFrog and Image is in Docker Hub.'
}
failure {
echo 'Pipeline failed. Check the logs.'
}
}
}