Jenkins 增加 Node 运行时自检与回退
This commit is contained in:
Vendored
+32
-3
@@ -3,8 +3,6 @@ pipeline {
|
|||||||
|
|
||||||
environment {
|
environment {
|
||||||
APP_NAME = 'no-whatever'
|
APP_NAME = 'no-whatever'
|
||||||
AMAP_KEY = credentials('amap-api-key')
|
|
||||||
DEEPSEEK_KEY = credentials('deepseek-api-key')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
triggers {
|
triggers {
|
||||||
@@ -18,6 +16,24 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Node Runtime') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
if (sh(returnStatus: true, script: 'command -v npm >/dev/null 2>&1') != 0) {
|
||||||
|
echo "System npm not found, trying Jenkins NodeJS tool 'node20'"
|
||||||
|
try {
|
||||||
|
def nodeHome = tool name: 'node20', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
|
||||||
|
env.PATH = "${nodeHome}/bin:${env.PATH}"
|
||||||
|
} catch (err) {
|
||||||
|
error "npm not found and Jenkins NodeJS tool 'node20' is unavailable. Please install NodeJS plugin and configure tool name 'node20'. Root cause: ${err}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sh 'node -v'
|
||||||
|
sh 'npm -v'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Install Dependencies') {
|
stage('Install Dependencies') {
|
||||||
steps {
|
steps {
|
||||||
sh 'npm ci'
|
sh 'npm ci'
|
||||||
@@ -42,16 +58,29 @@ pipeline {
|
|||||||
}
|
}
|
||||||
sh 'npm run test:e2e'
|
sh 'npm run test:e2e'
|
||||||
}
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
archiveArtifacts artifacts: 'playwright-report/**,test-results/**', allowEmptyArchive: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Docker Image') {
|
stage('Build Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
|
withCredentials([
|
||||||
|
string(credentialsId: 'amap-api-key', variable: 'AMAP_KEY')
|
||||||
|
]) {
|
||||||
sh "docker build --build-arg NEXT_PUBLIC_AMAP_API_KEY=${AMAP_KEY} -t ${APP_NAME}:${BUILD_NUMBER} -t ${APP_NAME}:latest ."
|
sh "docker build --build-arg NEXT_PUBLIC_AMAP_API_KEY=${AMAP_KEY} -t ${APP_NAME}:${BUILD_NUMBER} -t ${APP_NAME}:latest ."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
steps {
|
steps {
|
||||||
|
withCredentials([
|
||||||
|
string(credentialsId: 'amap-api-key', variable: 'AMAP_KEY'),
|
||||||
|
string(credentialsId: 'deepseek-api-key', variable: 'DEEPSEEK_KEY')
|
||||||
|
]) {
|
||||||
sh """
|
sh """
|
||||||
docker stop ${APP_NAME} || true
|
docker stop ${APP_NAME} || true
|
||||||
docker rm ${APP_NAME} || true
|
docker rm ${APP_NAME} || true
|
||||||
@@ -71,6 +100,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
@@ -78,7 +108,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "Build #${BUILD_NUMBER} failed"
|
echo "Build #${BUILD_NUMBER} failed"
|
||||||
archiveArtifacts artifacts: 'playwright-report/**,test-results/**', allowEmptyArchive: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user