forked from jason-liu22/netflix-clone-react-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
130 lines (101 loc) · 3.73 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
pipeline {
agent any
tools{
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
}
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
stage("Git Checkout"){
steps{
git branch: 'main', url: 'https://github.com/nahidkishore/Netflix-clone.git'
}
}
stage("Trivy FS Scan"){
steps{
sh "trivy fs . > trivy.txt"
}
}
stage("OWASP Dependency Check"){
steps{
dependencyCheck additionalArguments: '--scan ./' , odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
-Dsonar.projectKey=Netflix '''
}
}
}
stage("SonarQube Quality Gate"){
steps {
waitForQualityGate abortPipeline: false, credentialsId: 'sonar-token'
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage("Build and Push to Docker Hub"){
steps{
echo 'login into docker hub and pushing image....'
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]){
sh "docker build . -t netflix-app --build-arg TMDB_V3_API_KEY=c98fdab914b9bacee19db52aeb2707f4"
sh "docker tag netflix-app ${env.dockerHubUser}/netflix-app:latest"
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
sh "docker push ${env.dockerHubUser}/netflix-app:latest"
}
}
}
stage("Deploy to Container"){
steps{
sh " docker run -d --name netflix-app -p 8085:80 nahid0002/netflix-app:latest "
}
}
stage("TRIVY"){
steps{
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]){
sh "trivy image ${env.dockerHubUser}/netflix-app:latest > trivy.txt"
}
}
}
stage('Deploy to kubernetes') {
steps {
script {
withKubeConfig([credentialsId: 'K8s', serverUrl: '']) {
sh ('kubectl apply -f deployment.yaml')
}
}
}
}
}
post {
always {
emailext (
subject: "Pipeline Status: ${BUILD_NUMBER}",
body: '''<html>
<body>
<p>Build Status: ${BUILD_STATUS}</p>
<p>Build Number: ${BUILD_NUMBER}</p>
<p>Check the <a href="${BUILD_URL}">console output</a>.</p>
</body>
</html>''',
to: '[email protected]',
from: '[email protected]',
replyTo: '[email protected]',
mimeType: 'text/html'
)
}
}
}