Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
67 lines (60 loc) · 2.35 KB
/
Copy pathJenkinsfile
File metadata and controls
67 lines (60 loc) · 2.35 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
pipeline {
agent any
environment {
AWS_ACCESS_KEY = credentials('AWS_ACCESS_KEY')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
AWS_DEFAULT_REGION = "us-east-1"
CLUSTER_NAME = "landmark-eks-cluster"
DOCKER_REPO = "landmark/devopsapp"
IMAGE_TAG = "${BUILD_NUMBER}"
}
stages {
stage('Git Checkout') {
steps {
echo 'Cloning project codebase...'
git branch: 'main', url: 'https://github.com/LandmakTechnology/devopsapp.git'
}
}
stage('Build Docker Image') {
steps {
script {
sh "docker build -t ${DOCKER_REPO}:${IMAGE_TAG} ."
sh "docker tag ${DOCKER_REPO}:${IMAGE_TAG} ${DOCKER_REPO}:latest"
sh 'docker images'
}
}
}
stage('Docker Login & Push') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'DOCKER', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh 'echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin'
sh "docker push ${DOCKER_REPO}:${IMAGE_TAG}"
sh "docker push ${DOCKER_REPO}:latest"
}
}
}
}
stage('Deploy to EKS') {
steps {
script {
sh "aws eks update-kubeconfig --name ${CLUSTER_NAME} --region ${AWS_DEFAULT_REGION}"
sh "sed -i 's|chafah/devopsapp:latest|${DOCKER_REPO}:${IMAGE_TAG}|g' kubernetes/03-deployment/deployment.yaml"
sh "kubectl apply -f kubernetes/01-namespace/namespace.yaml"
sh "kubectl apply -f kubernetes/04-configmap/configmap.yaml"
sh "kubectl apply -f kubernetes/03-deployment/deployment.yaml"
sh "kubectl apply -f kubernetes/03-deployment/service.yaml"
sh "kubectl get svc -n landmark"
}
}
}
}
post {
success {
echo 'Pipeline completed successfully! Application deployed to EKS.'
}
failure {
echo 'Pipeline failed. Check the logs for details.'
}
}
}