Jenkins file edit
Some checks failed
test/timeline-frontend/pipeline/head There was a failure building this commit

This commit is contained in:
2025-12-30 11:47:21 +08:00
parent dd289d6f4e
commit 251e440108

67
Jenkinsfile vendored
View File

@@ -156,44 +156,22 @@ pipeline {
} }
stage('Deploy to Environment') { stage('Deploy to Environment') {
parallel {
stage('Deploy to Dev') {
when {
expression { params.DEPLOY_TARGET == 'dev' }
}
steps {
deployToEnvironment('dev')
}
}
stage('Deploy to Staging') {
when {
anyOf {
expression { params.DEPLOY_TARGET == 'staging' }
expression { params.DEPLOY_TARGET == 'prod' }
}
}
steps {
deployToEnvironment('staging')
}
}
stage('Deploy to Production') {
when {
expression { params.DEPLOY_TARGET == 'prod' }
}
steps { steps {
script { script {
input message: "确定要部署到生产环境吗?", ok: "是", parameters: [ // 创建或更新docker-compose文件
choice(name: 'CONFIRM_DEPLOY', choices: ['yes', 'no'], description: '确认部署') def composeContent = getComposeFileContent()
] writeFile file: 'docker-compose.yml', text: composeContent
if (params.CONFIRM_DEPLOY == 'yes') {
deployToEnvironment('prod') // 拉取最新镜像
} else { sh 'docker compose pull'
error "部署被取消"
} // 停止旧容器
} sh 'docker compose down || true'
}
// 启动新容器
sh 'docker compose up -d'
echo "所有服务已部署完成"
} }
} }
} }
@@ -292,3 +270,20 @@ def getPortForEnvironment(String env) {
return '80' return '80'
} }
} }
// 生成docker-compose文件内容的函数
def getComposeFileContent(buildNumber) {
def imageToDeploy = "${DOCKER_IMAGE}:latest"
def containerName = "${PROJECT_NAME}-${env}"
return """
version: '3.8'
services:
timeline-story-service:
image: ${imageToDeploy}
container_name: ${containerName}
ports:
- "3000:80"
extra_hosts:
- "host.docker.internal:host-gateway"
"""
}