-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile
114 lines (103 loc) · 3.24 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
pipeline {
agent any
environment {
SONAR_SCANNER_VERSION = '5.0.1.3006'
SONAR_SCANNER_HOME = "$HOME/.sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-linux"
PATH = "${SONAR_SCANNER_HOME}/bin:$PATH"
SONAR_SCANNER_OPTS = "-server"
}
stages {
stage('Checkout Code') {
steps {
git branch: 'master',
url: 'https://github.com/GGAshwin/BloggerLine.git'
}
}
stage('Install Dependencies') {
steps {
sh '''
cd client
npm install
cd ../api
npm install
'''
}
}
stage("Build Docker Images"){
steps{
sh '''
docker-compose pull
docker compose build
docker compose up --build -d
'''
}
}
stage('Push Docker Images') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'Docker', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh '''
docker login -u $USERNAME -p $PASSWORD
docker-compose push
'''
}
}
}
}
stage('Build React') {
steps {
sh '''
cd client
npm run build
'''
}
}
stage('Setup SonarQube Scanner') {
steps {
script {
sh '''
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
chmod +x $SONAR_SCANNER_HOME/bin/sonar-scanner
'''
}
}
}
stage('Verify SonarQube Scanner') {
steps {
sh 'sonar-scanner --version'
}
}
stage('SonarQube Analysis') {
steps {
script {
sh '''
sonar-scanner \
-Dsonar.projectKey=Bloggerline \
-Dsonar.sources=. \
-Dsonar.host.url=http://54.145.74.209:9000 \
-Dsonar.token=sqp_2bd303385bbd5038e952edd8615e357935182a93
'''
}
}
}
stage('Deploy') {
steps {
sh '''
sudo rm -rf /var/www/bloggerline/*
sudo cp -r "${WORKSPACE}/client/build/" /var/www/bloggerline/
'''
}
}
// stage('Deploy Using Jenkins') {
// steps {
// sh '''
// kubectl delete pods -l app=bloggerline-client --grace-period=0 --force
// kubectl apply -f deployment.yaml
// kubectl apply -f service.yaml
// kubectl get services
// '''
// }
// }
}
}