-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile
75 lines (68 loc) · 2.77 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
pipeline {
agent any
environment {
DOCKER_HUB_CREDENTIALS_ID = 'dockerhub-creds' // Jenkins credentials ID for Docker Hub
ARGOCD_CREDENTIALS_ID = 'argocd-token' // ArgoCD API token stored in Jenkins credentials
FRONTEND_IMAGE_NAME = 'milinddethe15/chat-cluster-frontend'
BACKEND_IMAGE_NAME = 'milinddethe15/chat-cluster-backend'
FRONTEND_DIR = 'frontend'
BACKEND_DIR = 'backend'
ARGOCD_SERVER = '' // Update with the correct ArgoCD external IP
K8S_NAMESPACE = 'chat-cluster'
}
stages {
stage('Clone Repository') {
steps {
git url: 'https://github.com/milinddethe15/chat-cluster.git', branch: 'main'
}
}
stage('Build & Push Docker Images') {
parallel {
stage('Build & Push Frontend') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_HUB_CREDENTIALS_ID}") {
def frontendImage = docker.build("${FRONTEND_IMAGE_NAME}:latest", "-f ${FRONTEND_DIR}/Dockerfile ${FRONTEND_DIR}")
frontendImage.push('latest')
}
}
}
}
stage('Build & Push Backend') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_HUB_CREDENTIALS_ID}") {
def backendImage = docker.build("${BACKEND_IMAGE_NAME}:latest", "-f Dockerfile .")
backendImage.push('latest')
}
}
}
}
}
}
stage('Deploy to Kubernetes via ArgoCD') {
steps {
script {
withCredentials([string(credentialsId: "${ARGOCD_CREDENTIALS_ID}", variable: 'ARGOCD_TOKEN')]) {
sh '''
# Log in to ArgoCD
argocd login $ARGOCD_SERVER --grpc-web --insecure --auth-token $ARGOCD_TOKEN
# Sync the application
argocd app sync chat-cluster --grpc-web --insecure
# Wait for sync to complete
argocd app wait chat-cluster --health --sync
'''
}
}
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}