fix: 简化 Jenkinsfile,移除未配置的凭据依赖
This commit is contained in:
Vendored
+12
-36
@@ -2,9 +2,7 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
APP_NAME = 'no-whatever'
|
APP_NAME = 'no-whatever'
|
||||||
DEPLOY_HOST = credentials('deploy-server-host') // 在 Jenkins 凭据中配置
|
|
||||||
DEPLOY_USER = credentials('deploy-server-user')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
triggers {
|
triggers {
|
||||||
@@ -20,44 +18,22 @@ pipeline {
|
|||||||
|
|
||||||
stage('Build Docker Image') {
|
stage('Build Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh "docker build -t ${APP_NAME}:${BUILD_NUMBER} -t ${APP_NAME}:latest ."
|
||||||
docker.build("${APP_NAME}:${BUILD_NUMBER}")
|
|
||||||
docker.build("${APP_NAME}:latest")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh """
|
||||||
// 方案 A: Jenkins 和部署机是同一台服务器
|
docker stop ${APP_NAME} || true
|
||||||
sh """
|
docker rm ${APP_NAME} || true
|
||||||
docker stop ${APP_NAME} || true
|
docker run -d \
|
||||||
docker rm ${APP_NAME} || true
|
--name ${APP_NAME} \
|
||||||
docker run -d \
|
-p 3000:3000 \
|
||||||
--name ${APP_NAME} \
|
-v ${APP_NAME}-data:/app/data \
|
||||||
-p 3000:3000 \
|
--restart unless-stopped \
|
||||||
-v ${APP_NAME}-data:/app/data \
|
${APP_NAME}:latest
|
||||||
--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
|
|
||||||
// """
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user