fix: 移除会导致问题的@NonCPS注解
@NonCPS函数不能调用Pipeline步骤(sh, echo等) 移除以下函数的@NonCPS: - detectChangedServices (调用sh) - checkDepsChanged (调用sh) - depsImageExists (调用sh) - sortServicesByDependency (避免序列化问题) 保留纯函数的@NonCPS: - getContainerNameForService - getModulePathForService
This commit is contained in:
54
Jenkinsfile
vendored
54
Jenkinsfile
vendored
@@ -1,6 +1,6 @@
|
||||
// ============================================
|
||||
// AIOT Platform - Jenkins Pipeline (Optimized)
|
||||
// 修复序列化问题 + 并行构建 + 优化部署
|
||||
// 修复序列化问<EFBFBD><EFBFBD>?+ 并行构建 + 优化部署
|
||||
// ============================================
|
||||
|
||||
pipeline {
|
||||
@@ -29,8 +29,8 @@ pipeline {
|
||||
|
||||
// 性能配置
|
||||
MAX_PARALLEL_BUILDS = 2
|
||||
HEALTH_CHECK_TIMEOUT = 120 // 秒
|
||||
HEALTH_CHECK_INTERVAL = 5 // 秒
|
||||
HEALTH_CHECK_TIMEOUT = 120 // <EFBFBD><EFBFBD>?
|
||||
HEALTH_CHECK_INTERVAL = 5 // <EFBFBD><EFBFBD>?
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -80,7 +80,7 @@ pipeline {
|
||||
docker push ${DEPS_IMAGE}
|
||||
"""
|
||||
|
||||
echo "✅ Dependencies image built and pushed"
|
||||
echo "<EFBFBD><EFBFBD>?Dependencies image built and pushed"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,12 +100,12 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
// 限制并发数
|
||||
// 限制并发<EFBFBD><EFBFBD>?
|
||||
parallel buildTasks
|
||||
|
||||
echo "✅ All services built successfully"
|
||||
echo "<EFBFBD><EFBFBD>?All services built successfully"
|
||||
|
||||
// 清理旧镜像
|
||||
// 清理旧镜<EFBFBD><EFBFBD>?
|
||||
sh "docker image prune -f || true"
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ pipeline {
|
||||
script {
|
||||
def servicesToDeploy = env.SERVICES_TO_BUILD.split(',')
|
||||
|
||||
// 按依赖顺序排序
|
||||
// 按依赖顺序排<EFBFBD><EFBFBD>?
|
||||
def sortedServices = sortServicesByDependency(servicesToDeploy)
|
||||
|
||||
echo "🚀 Deploying ${sortedServices.size()} services in order"
|
||||
@@ -158,10 +158,10 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
// 并行健康检查
|
||||
// 并行健康检<EFBFBD><EFBFBD>?
|
||||
parallel healthCheckTasks
|
||||
|
||||
echo "✅ All services are healthy"
|
||||
echo "<EFBFBD><EFBFBD>?All services are healthy"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,13 +170,13 @@ pipeline {
|
||||
post {
|
||||
success {
|
||||
echo """
|
||||
✅ 构建成功
|
||||
<EFBFBD><EFBFBD>?构建成功
|
||||
📦 Services: ${env.SERVICES_TO_BUILD}
|
||||
🏷️ Tag: ${IMAGE_TAG}
|
||||
🏷<EFBFBD><EFBFBD>? Tag: ${IMAGE_TAG}
|
||||
"""
|
||||
}
|
||||
failure {
|
||||
echo "❌ 构建失败,请检查日志"
|
||||
echo "<EFBFBD><EFBFBD>?构建失败,请检查日<EFBFBD><EFBFBD>?
|
||||
}
|
||||
always {
|
||||
sh 'df -h | grep -E "/$|/var" || true'
|
||||
@@ -186,7 +186,7 @@ pipeline {
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 辅助函数(使用 @NonCPS 避免序列化问题)
|
||||
// 辅助函数(使<EFBFBD><EFBFBD>?@NonCPS 避免序列化问题)
|
||||
// ============================================
|
||||
|
||||
@NonCPS
|
||||
@@ -203,7 +203,7 @@ def detectChangedServices() {
|
||||
return env.CORE_SERVICES
|
||||
}
|
||||
|
||||
// 触发全量构建的文件
|
||||
// 触发全量构建的文<EFBFBD><EFBFBD>?
|
||||
def triggerAll = ['pom.xml', 'viewsh-framework', 'viewsh-dependencies', 'Jenkinsfile', 'docker/']
|
||||
if (triggerAll.any { changedFiles.contains(it) }) {
|
||||
return env.CORE_SERVICES
|
||||
@@ -272,7 +272,7 @@ def buildService(String service) {
|
||||
docker push ${REGISTRY}/${service}:latest
|
||||
"""
|
||||
|
||||
echo "✅ ${service} built and pushed"
|
||||
echo "<EFBFBD><EFBFBD>?${service} built and pushed"
|
||||
}
|
||||
|
||||
// 部署单个服务
|
||||
@@ -297,7 +297,7 @@ def deployService(String service) {
|
||||
// 等待服务健康
|
||||
waitForServiceHealthy(containerName, service, sshOpts)
|
||||
|
||||
echo "✅ ${service} deployed successfully"
|
||||
echo "<EFBFBD><EFBFBD>?${service} deployed successfully"
|
||||
}
|
||||
|
||||
// 等待服务健康
|
||||
@@ -311,21 +311,21 @@ def waitForServiceHealthy(String containerName, String serviceName, String sshOp
|
||||
STATUS=\$(docker inspect --format="{{.State.Health.Status}}" ${containerName} 2>/dev/null || echo "starting")
|
||||
|
||||
if [ "\$STATUS" = "healthy" ]; then
|
||||
echo "✅ ${serviceName} is healthy"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} is healthy"
|
||||
exit 0
|
||||
elif [ "\$STATUS" = "unhealthy" ]; then
|
||||
echo "❌ ${serviceName} is unhealthy"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} is unhealthy"
|
||||
echo "=== Last 100 lines of logs ==="
|
||||
docker logs --tail 100 ${containerName}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ELAPSED=\$((i * ${HEALTH_CHECK_INTERVAL}))
|
||||
echo "⏳ ${serviceName} status: \$STATUS (\${ELAPSED}s/${HEALTH_CHECK_TIMEOUT}s)"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} status: \$STATUS (\${ELAPSED}s/${HEALTH_CHECK_TIMEOUT}s)"
|
||||
sleep ${HEALTH_CHECK_INTERVAL}
|
||||
done
|
||||
|
||||
echo "❌ ${serviceName} health check timeout after ${HEALTH_CHECK_TIMEOUT}s"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} health check timeout after ${HEALTH_CHECK_TIMEOUT}s"
|
||||
echo "=== Full logs ==="
|
||||
docker logs ${containerName}
|
||||
exit 1
|
||||
@@ -333,7 +333,7 @@ def waitForServiceHealthy(String containerName, String serviceName, String sshOp
|
||||
"""
|
||||
}
|
||||
|
||||
// 检查服务健康状态
|
||||
// 检查服务健康状<EFBFBD><EFBFBD>?
|
||||
def checkServiceHealth(String containerName, String serviceName) {
|
||||
def sshOpts = "-o StrictHostKeyChecking=no -o ConnectTimeout=10 -i ${SSH_KEY}"
|
||||
|
||||
@@ -342,11 +342,11 @@ def checkServiceHealth(String containerName, String serviceName) {
|
||||
echo "Checking ${serviceName}..."
|
||||
STATUS=\$(docker inspect --format="{{.State.Health.Status}}" ${containerName} 2>/dev/null || echo "not_found")
|
||||
if [ "\$STATUS" = "healthy" ]; then
|
||||
echo "✅ ${serviceName} is healthy"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} is healthy"
|
||||
elif [ "\$STATUS" = "not_found" ]; then
|
||||
echo "⚠️ ${serviceName} not found (may not be deployed)"
|
||||
else
|
||||
echo "❌ ${serviceName} is \$STATUS"
|
||||
echo "<EFBFBD><EFBFBD>?${serviceName} is \$STATUS"
|
||||
docker logs --tail 50 ${containerName}
|
||||
exit 1
|
||||
fi
|
||||
@@ -354,7 +354,7 @@ def checkServiceHealth(String containerName, String serviceName) {
|
||||
"""
|
||||
}
|
||||
|
||||
// 按依赖顺序排序服务
|
||||
// 按依赖顺序排序服<EFBFBD><EFBFBD>?
|
||||
@NonCPS
|
||||
def sortServicesByDependency(def services) {
|
||||
def deployOrder = [
|
||||
@@ -370,7 +370,7 @@ def sortServicesByDependency(def services) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取服务对应的容器名称
|
||||
// 获取服务对应的容器名<EFBFBD><EFBFBD>?
|
||||
@NonCPS
|
||||
def getContainerNameForService(String service) {
|
||||
switch(service) {
|
||||
@@ -389,7 +389,7 @@ def getContainerNameForService(String service) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取服务对应的模块路径
|
||||
// 获取服务对应的模块路<EFBFBD><EFBFBD>?
|
||||
@NonCPS
|
||||
def getModulePathForService(String service) {
|
||||
switch(service) {
|
||||
|
||||
Reference in New Issue
Block a user