Files
no-whatever/Jenkinsfile
T
kurihada 76bd7b4756 ci: 添加 Docker + Jenkins 自动化部署配置
- Dockerfile 多阶段构建,standalone 模式输出
- Jenkinsfile 定义 GitLab 触发的 CI/CD 流水线
- docker-compose.yml 简化部署
- next.config.ts 开启 standalone 输出
2026-02-25 12:10:32 +08:00

74 lines
2.3 KiB
Groovy

pipeline {
agent any
environment {
APP_NAME = 'no-whatever'
DEPLOY_HOST = credentials('deploy-server-host') // 在 Jenkins 凭据中配置
DEPLOY_USER = credentials('deploy-server-user')
}
triggers {
gitlab(triggerOnPush: true, branchFilterType: 'All')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build Docker Image') {
steps {
script {
docker.build("${APP_NAME}:${BUILD_NUMBER}")
docker.build("${APP_NAME}:latest")
}
}
}
stage('Deploy') {
steps {
script {
// 方案 A: Jenkins 和部署机是同一台服务器
sh """
docker stop ${APP_NAME} || true
docker rm ${APP_NAME} || true
docker run -d \
--name ${APP_NAME} \
-p 3000:3000 \
-v ${APP_NAME}-data:/app/data \
--restart unless-stopped \
${APP_NAME}:latest
"""
// 方案 B: 部署到远程服务器 (取消注释并注释掉方案 A)
// sh """
// docker save ${APP_NAME}:latest | \
// ssh ${DEPLOY_USER}@${DEPLOY_HOST} 'docker load'
// ssh ${DEPLOY_USER}@${DEPLOY_HOST} << 'EOF'
// docker stop ${APP_NAME} || true
// docker rm ${APP_NAME} || true
// docker run -d \
// --name ${APP_NAME} \
// -p 3000:3000 \
// -v ${APP_NAME}-data:/app/data \
// --restart unless-stopped \
// ${APP_NAME}:latest
// EOF
// """
}
}
}
}
post {
success {
echo "Deployed ${APP_NAME} build #${BUILD_NUMBER} successfully"
}
failure {
echo "Build #${BUILD_NUMBER} failed"
}
}
}