SiteFrontend/Jenkinsfile
Teriuihi 2a56144bbc Enhance npm cache clean error handling in Jenkinsfile
Wrapped npm cache clean command in a try-catch block to improve error handling. This ensures that the build process can proceed even if the npm cache clean step fails. Added an informational echo message for better diagnostics in case of failure.
2024-08-10 03:21:16 +02:00

80 lines
2.9 KiB
Groovy

pipeline {
agent any
environment {
MAX_RETRIES = 5
}
stages {
stage('Gradle') {
steps {
script {
def retryCount = 0
def success = false
// Clean npm cache and try normal install and npm ci once
try {
sh 'npm cache clean --force'
} catch (Exception e0) {
echo 'npm cache clean --force failed trying more things'
}
try {
sh 'npm install'
success = true
} catch (Exception e1) {
echo "npm install failed, trying npm ci..."
try {
sh 'npm ci'
success = true
} catch (Exception e2) {
echo "npm ci failed, proceeding to retry with --legacy-peer-deps and --force..."
}
}
// Retry with --legacy-peer-deps and --force if necessary
while (retryCount < MAX_RETRIES.toInteger() && !success) {
try {
sh 'npm install --legacy-peer-deps'
success = true
} catch (Exception e3) {
try {
sh 'npm install --force'
success = true
} catch (Exception e4) {
retryCount++
echo "Retry ${retryCount}/${MAX_RETRIES} failed"
}
}
try {
sh 'npm install --legacy-peer-deps --force'
success = true
} catch (Exception e4) {
echo "npm install --legacy-peer-deps --force failed"
}
}
if (!success) {
error "Failed to install dependencies after ${MAX_RETRIES} attempts"
}
sh 'npm run build'
}
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/**', followSymlinks: false
}
}
stage('discord') {
when {
anyOf {
branch 'main'
branch 'master'
}
}
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}