11pipeline {
22 agent any
3- options { timestamps() }
4- triggers { pollSCM(' H/5 * * * *' ) }
3+ tools { nodejs ' Node18' } // must match the Name field in your screenshot
54
65 stages {
76 stage(' Checkout' ) {
@@ -13,75 +12,33 @@ pipeline {
1312 stage(' Install Dependencies' ) {
1413 steps {
1514 sh ' npm ci || npm install'
16- sh ' node -v && npm -v'
1715 }
1816 }
1917
2018 stage(' Run Tests' ) {
2119 steps {
2220 sh ' npm test || true'
2321 }
24- post {
25- always {
26- junit allowEmptyResults : true , testResults : ' reports/**/*.xml'
27- }
28- }
2922 }
3023
31- stage(' Generate Coverage Report ' ) {
24+ stage(' Coverage' ) {
3225 steps {
3326 sh ' npm run coverage || true'
3427 }
35- post {
36- always { archiveArtifacts artifacts : ' coverage/**' , allowEmptyArchive : true }
37- }
3828 }
3929
40- stage(' NPM Audit (Security Scan) ' ) {
30+ stage(' NPM Audit' ) {
4131 steps {
4232 sh ' npm audit --audit-level=low || true'
43- sh ' npm audit --json > npm-audit.json || true'
44- }
45- post {
46- always { archiveArtifacts artifacts : ' npm-audit.json' , allowEmptyArchive : true }
4733 }
4834 }
4935
5036 stage(' SonarCloud Analysis' ) {
51- environment {
52- SC_VERSION = ' 5.0.1.3006'
53- }
5437 steps {
5538 withCredentials([string(credentialsId : ' SONAR_TOKEN' , variable : ' SONAR_TOKEN' )]) {
56- sh '''
57- set -e
58- TOOLS_DIR="$WORKSPACE/.tools"
59- mkdir -p "$TOOLS_DIR"
60- SC_DIR="$TOOLS_DIR/sonar-scanner-$SC_VERSION"
61-
62- if [ ! -x "$SC_DIR/bin/sonar-scanner" ]; then
63- echo "Downloading sonar-scanner-cli ${SC_VERSION}..."
64- curl -fsSL -o "$TOOLS_DIR/scanner.zip" \
65- "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SC_VERSION}-linux.zip"
66- unzip -q "$TOOLS_DIR/scanner.zip" -d "$TOOLS_DIR"
67- mv "$TOOLS_DIR/sonar-scanner-${SC_VERSION}-linux" "$SC_DIR"
68- fi
69-
70- export PATH="$SC_DIR/bin:$PATH"
71-
72- # Ensure coverage file exists
73- if [ ! -f coverage/lcov.info ]; then
74- echo "Generating coverage report..."
75- npm run coverage || true
76- fi
77-
78- sonar-scanner -Dsonar.login="$SONAR_TOKEN"
79- '''
39+ sh ' sonar-scanner -Dsonar.login=$SONAR_TOKEN || true'
8040 }
8141 }
82- post {
83- always { archiveArtifacts artifacts : ' **/.scannerwork/**/*.log' , allowEmptyArchive : true }
84- }
8542 }
8643 }
8744}
0 commit comments