fix:加入健康检查

This commit is contained in:
2025-07-27 19:38:00 +08:00
parent 13ade2e001
commit 239de5fd61
Vendored
+15 -11
View File
@@ -58,21 +58,25 @@ pipeline {
}
}
stage('Run Docker Container') {
stage('Check Docker Status') {
agent any
steps {
sh '''
docker rm -f $CONTAINER_NAME || true
docker run -d --name $CONTAINER_NAME \\
-p $HOST_PORT:$CONTAINER_PORT \\
--health-cmd="curl -f http://localhost:$CONTAINER_PORT || exit 1" \\
--health-interval=10s \\
--health-timeout=5s \\
--health-retries=3 \\
$IMAGE_NAME
'''
script {
timeout(time: 60, unit: 'SECONDS') {
waitUntil {
def status = sh(
script: "docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME || echo 'no-healthcheck'",
returnStdout: true
).trim()
echo "Current container status: ${status}"
return (status == 'healthy')
}
}
}
}
}
}
}