-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
66 lines (63 loc) · 1.82 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
pipeline {
agent any
environment {
EKS_CLUSTER_NAME = "dev-eks-cluster"
DOCKER_IMAGE = "dockerrepo/prodimage:latest"
KUBECONFIG = "etc/kubeconfig"
}
stages {
stage('Checkout') {
steps {
git branch: 'dev', url: 'https://github.com/evinw/app.git'
}
}
stage('Code Quality Check') {
steps {
//SonarQube scanner
sh 'sonar-scanner -Dsonar.projectKey=app -Dsonar.sources=. -Dsonar.host.url=http://sonarqube-server'
}
}
stage('Build Docker Image') {
steps {
dir('docker') {
script {
sh "docker build -t $DOCKER_IMAGE ."
sh "trivy image $DOCKER_IMAGE"
sh "docker push $DOCKER_IMAGE"
}
}
}
}
stage('Run Tests') {
steps {
sh './gradlew test'
}
}
stage('Deploy to EKS') {
steps {
script {
withAWS(credentials: 'aws-credentials') {
sh "aws eks update-kubeconfig --name $EKS_CLUSTER_NAME"
}
dir('k8s/dev') {
sh "kubectl apply -f deployment.yaml"
sh "kubectl apply -f service.yaml"
}
}
}
}
}
post {
success {
echo 'Deployment was successful.'
}
failure {
echo 'Deployment failed. Initiating rollback...'
// rollback step
// sh "kubectl rollout undo deployment/dev-deployment"
}
always {
echo 'Deployment complete.'
}
}
}