diff --git a/Dockerfile b/Dockerfile index 0f0dcf4..d73c8c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ FROM nginx:alpine + +# 安装 curl 用于健康检查 +RUN apk add --no-cache curl + COPY dist/ /usr/share/nginx/html/ EXPOSE 80 diff --git a/Jenkinsfile b/Jenkinsfile index 9080bd1..54b0df9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,5 +57,22 @@ pipeline { ''' } } + + stage('Run Docker Container') { + 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 + ''' + } + } + } }