fix:加入健康检查
This commit is contained in:
Vendored
+15
-11
@@ -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')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user