-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile-prod
98 lines (88 loc) · 2.96 KB
/
Jenkinsfile-prod
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pipeline {
agent any
tools {
nodejs 'nodeProd'
}
environment {
SCANNER_HOME = tool 'sonar-prod'
PROJECT_ID = "${PROJECT_ID}"
CLUSTER_NAME = "${CLUSTER_NAME}"
LOCATION = "${LOCATION}"
CREDENTIALS_ID = 'jenkins-gke-key'
}
stages {
stage('Git Checkout') {
steps {
git branch: 'main', credentialsId: 'git-cred', url: 'https://github.com/ChetanThapliyal/YelpCampAPP'
}
}
stage('Install Package Dependencies') {
steps {
sh "npm install"
}
}
stage('Unit Tests') {
steps {
sh "npm test"
}
}
stage('Trivy FS Scan') {
steps {
sh "trivy fs --format table -o fs-report.html ."
}
}
stage('Sonarqube') {
steps {
withSonarQubeEnv('sonar') {
sh "$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectKey=Campground -Dsonar.projectName=Campground"
}
}
}
stage('Build and Tag Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker-prod') {
sh "docker image build -t che01tan/camp:latest ."
}
}
}
}
stage('Docker Image Scan') {
steps {
sh "trivy image --format table -o trivy-image-report.html che01tan/camp:latest"
}
}
stage('Push Docker Image') {
steps {
script {
withDockerRegistry([credentialsId: 'docker-cred', toolName: 'docker-prod']) {
sh "docker push che01tan/camp:latest"
}
}
}
}
// stage('Configure kubectl') {
// steps {
// withCredentials([file(credentialsId: 'gke-cred-file', variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) {
// sh '''
// gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
// gcloud container clusters get-credentials ${CLUSTER_NAME} --zone ${LOCATION} --project ${PROJECT_ID}
// '''
// }
// }
// }
stage('Deploy to GKE') {
steps {
step([
$class: 'KubernetesEngineBuilder',
projectId: env.PROJECT_ID,
clusterName: env.CLUSTER_NAME,
location: env.LOCATION,
manifestPattern: 'k8/deployment.yaml',
credentialsId: env.CREDENTIALS_ID,
verifyDeployments: true])
echo "Deployment Finished"
}
}
}
}