-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathJenkinsfile
69 lines (63 loc) · 2.04 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
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials') // DockerHub credentials configured in Jenkins
DOCKERHUB_REPO = 'cubensquare/vanakkam-world'
DOCKER_IMAGE_TAG = 'latest'
KUBECONFIG_CREDENTIALS = credentials('kubeconfig-credentials') // Kubernetes kubeconfig credentials
}
tools {
maven 'mymaven'
}
stages {
stage('Checkout Code') {
steps {
echo 'Cloning the repository...'
git url: 'https://github.com/mgsgoms/vanakkam-world', branch: 'master'
}
}
stage('Build with Maven') {
steps {
echo 'Building the project using Maven...'
sh 'mvn clean install'
}
}
stage('Build Docker Image') {
steps {
echo 'Building Docker image...'
sh '''
docker build -t $DOCKERHUB_REPO:$DOCKER_IMAGE_TAG .
'''
}
}
stage('Push Docker Image') {
steps {
echo 'Pushing Docker image to DockerHub...'
sh '''
echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin
docker push $DOCKERHUB_REPO:$DOCKER_IMAGE_TAG
'''
}
}
stage('Deploy to Kubernetes') {
steps {
echo 'Deploying the application to Kubernetes...'
withCredentials([file(credentialsId: 'kubeconfig-credentials', variable: 'KUBECONFIG')]) {
sh '''
export KUBECONFIG=$KUBECONFIG
kubectl apply -f k8s-deployment.yaml
kubectl apply -f k8s-service.yaml
'''
}
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}