From 2d3512ac4ccbc815fd3375c4ca815167ec52dc53 Mon Sep 17 00:00:00 2001 From: guo <1716967236@qq.com> Date: Sun, 26 Oct 2025 12:55:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(N/A):=E9=85=8D=E7=BD=AE=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile-dev | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Jenkinsfile-dev diff --git a/Jenkinsfile-dev b/Jenkinsfile-dev new file mode 100644 index 0000000..f4793b6 --- /dev/null +++ b/Jenkinsfile-dev @@ -0,0 +1,89 @@ +pipeline { + agent none // 全局不指定,局部单独声明 + environment { + IMAGE_NAME = 'lpt-fe:0.0' + CONTAINER_NAME = 'LPT_FE' + HOST_PORT = '8155' + CONTAINER_PORT = '80' + } + stages { + stage('Install Dependencies') { + agent { + docker { + image 'node:20-alpine' + args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' + } + } + steps { + sh ''' + npm config set cache /.npm + npm install + ''' + } + } + + stage('Type Check & Build') { + agent { + docker { + image 'node:20-alpine' + args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' + } + } + steps { + sh ''' + npm run type-check + npm run build + ''' + } + } + + stage('Build Docker Image') { + agent any // Jenkins默认节点,有Docker命令 + steps { + sh ''' + docker build -t $IMAGE_NAME . + ''' + } + } + + 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:80 || exit 1" \\ + --health-interval=5s \\ + --health-retries=3 \\ + --restart=always \\ + $IMAGE_NAME + ''' + } + } + + stage('Check Docker Status') { + agent any + steps { + script { + def lastStatus = '' + timeout(time: 60, unit: 'SECONDS') { + waitUntil { + def status = sh( + script: "docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME || echo 'unhealthy'", + returnStdout: true + ).trim() + + if (status != lastStatus) { + echo "Container health: ${status}" + lastStatus = status + } + + return (status == 'healthy') + } + } + } + } + } + } +}