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

69
Jenkinsfile vendored
View File

@@ -156,46 +156,24 @@ pipeline {
}
stage('Deploy to Environment') {
parallel {
stage('Deploy to Dev') {
when {
expression { params.DEPLOY_TARGET == 'dev' }
}
steps {
deployToEnvironment('dev')
}
}
steps {
script {
// 创建或更新docker-compose文件
def composeContent = getComposeFileContent()
writeFile file: 'docker-compose.yml', text: composeContent
stage('Deploy to Staging') {
when {
anyOf {
expression { params.DEPLOY_TARGET == 'staging' }
expression { params.DEPLOY_TARGET == 'prod' }
}
}
steps {
deployToEnvironment('staging')
}
}
// 拉取最新镜像
sh 'docker compose pull'
stage('Deploy to Production') {
when {
expression { params.DEPLOY_TARGET == 'prod' }
}
steps {
script {
input message: "确定要部署到生产环境吗?", ok: "是", parameters: [
choice(name: 'CONFIRM_DEPLOY', choices: ['yes', 'no'], description: '确认部署')
]
if (params.CONFIRM_DEPLOY == 'yes') {
deployToEnvironment('prod')
} else {
error "部署被取消"
}
}
}
// 停止旧容器
sh 'docker compose down || true'
// 启动新容器
sh 'docker compose up -d'
echo "所有服务已部署完成"
}
}
}
}
}
@@ -292,3 +270,20 @@ def getPortForEnvironment(String env) {
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"
"""
}