-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
65 lines (61 loc) · 2.03 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
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.8.4-openjdk-17
command:
- cat
tty: true
volumeMounts:
- name: maven-cache
mountPath: /root/.m2
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command:
- /busybox/cat
tty: true
volumes:
- name: maven-cache
persistentVolumeClaim:
claimName: efs-pvc
'''
}
}
environment {
DOCKER_HUB_REPO = "techiescamp/jenkins-java-app"
IMAGE_TAG = "2.0.0"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build with Maven') {
steps {
container('maven') {
sh 'mvn -B -Dmaven.repo.local=/root/.m2/repository clean install -DskipTests'
}
}
}
stage('Build and Push Docker Image') {
steps {
container('kaniko') {
withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'DOCKER_HUB_USR', passwordVariable: 'DOCKER_HUB_PSW')]) {
script {
sh """
echo '{"auths":{"https://index.docker.io/v1/":{"auth":"'"\$(echo -n ${DOCKER_HUB_USR}:${DOCKER_HUB_PSW} | base64)"'"}}}' > /kaniko/.docker/config.json
/kaniko/executor --dockerfile="/Dockerfile" --context `pwd` --destination ${DOCKER_HUB_REPO}:${IMAGE_TAG}
"""
}
}
}
}
}
}
}