-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjenkinsfilesonarnodejs
More file actions
56 lines (51 loc) · 1.32 KB
/
jenkinsfilesonarnodejs
File metadata and controls
56 lines (51 loc) · 1.32 KB
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
pipeline {
agent any
environment {
SONARQUBE_URL = 'http://192.168.111.131:9000' /* Adjust SonarQube server URL if needed */
SONARQUBE_PROJECT_KEY = 'myproject'
}
stages {
stage('Checkout SCM') {
steps {
script {
checkoutSCM()
}
}
}
stage('Install Dependencies') {
steps {
script {
installDependencies()
}
}
}
stage('Analyze Code Quality') {
steps {
script {
analyzeCodeQuality()
}
}
}
}
}
def checkoutSCM() {
checkout scm: [
$class: 'GitSCM',
branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'https://github.com/amitopenwriteup/node-sonar-scanner.git']]
]
}
def installDependencies() {
sh 'npm install'
sh 'npm install sonar-scanner'
}
def analyzeCodeQuality() {
withCredentials([string(credentialsId: '5fdd614d-f6e8-4f1f-8154-1a31831301bd', variable: 'SONAR_TOKEN')]) {
sh '''
npx sonar-scanner \
-Dsonar.projectKey="$SONARQUBE_PROJECT_KEY" \
-Dsonar.host.url="$SONARQUBE_URL" \
-Dsonar.login="$SONAR_TOKEN"
'''
}
}