Handle npm install retries with fallback options
Added an environment variable for maximum retries and a script to handle npm install with fallback to npm ci and retry mechanisms using --legacy-peer-deps and --force options. This might fix npm sucking.
This commit is contained in:
parent
a8ea5c38f1
commit
7ab9e25eb5
48
Jenkinsfile
vendored
48
Jenkinsfile
vendored
|
|
@ -1,10 +1,52 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
environment {
|
||||||
|
MAX_RETRIES = 5
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Gradle') {
|
stage('Gradle') {
|
||||||
steps {
|
steps {
|
||||||
sh 'npm install --force --legacy-peer-dep'
|
script {
|
||||||
sh 'npm run build'
|
def retryCount = 0
|
||||||
|
def success = false
|
||||||
|
|
||||||
|
// Clean npm cache and try normal install and npm ci once
|
||||||
|
sh 'npm cache clean --force'
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
error "Failed to install dependencies after ${MAX_RETRIES} attempts"
|
||||||
|
}
|
||||||
|
|
||||||
|
sh 'npm run build'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Archive') {
|
stage('Archive') {
|
||||||
|
|
@ -18,4 +60,4 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user