forked from jaiswaladi246/3-Tier-Full-Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-file
101 lines (94 loc) · 3.02 KB
/
jenkins-file
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
pipeline {
agent any
tools {
nodejs 'nodejs22'
}
environment {
SCANNER_HOME= tool 'sonar-scanner'
IMAGE_TAG = "${BUILD_NUMBER}"
}
stages {
stage('Git Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Abdihakim-said/3-Tier-Full-Stack'
}
}
stage('Install 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('Docker Build and Tag') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolname: 'docker') {
sh "docker build -t abdihakimdevops/camp:1 ."
}
}
}
}
stage('Trivy Image Scan') {
steps {
sh "trivy image --format table -o fs-report.html abdihakimdevops/camp:1"
}
}
stage('Docker Push') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred') {
sh "docker push abdihakimdevops/camp:latest"
}
}
}
}
stage('Checkout K8S manifest SCM'){
steps {
git branch: 'main', credentialsId: 'github', url: 'https://github.com/Abdihakim-said/3-Tier-Full-Stack'
}
}
stage('Change Directory to manifests') {
steps {
dir('Manifests') {
script {
echo "Changed directory to manifests"
// Add any additional commands to run in the manifests directory here
}
}
}
}
stage('Update K8S manifest & push to Repo'){
steps {
script{
withCredentials([usernamePassword(credentialsId: 'github', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh '''
cat dss.yml
sed -i '' "s/32/${BUILD_NUMBER}/g" dss.yml
cat dss.yml
git add deploy.yaml
git commit -m 'Updated the deploy yaml | Jenkins Pipeline'
git remote -v
git push 'https://github.com/Abdihakim-said/3-Tier-Full-Stack' HEAD:main
'''
}
}
}
}
}
}