Jenkins file edit
Some checks failed
test/timeline-frontend/pipeline/head There was a failure building this commit
Some checks failed
test/timeline-frontend/pipeline/head There was a failure building this commit
This commit is contained in:
67
Jenkinsfile
vendored
67
Jenkinsfile
vendored
@@ -156,44 +156,22 @@ pipeline {
|
||||
}
|
||||
|
||||
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 {
|
||||
script {
|
||||
input message: "确定要部署到生产环境吗?", ok: "是", parameters: [
|
||||
choice(name: 'CONFIRM_DEPLOY', choices: ['yes', 'no'], description: '确认部署')
|
||||
]
|
||||
if (params.CONFIRM_DEPLOY == 'yes') {
|
||||
deployToEnvironment('prod')
|
||||
} else {
|
||||
error "部署被取消"
|
||||
}
|
||||
}
|
||||
}
|
||||
// 创建或更新docker-compose文件
|
||||
def composeContent = getComposeFileContent()
|
||||
writeFile file: 'docker-compose.yml', text: composeContent
|
||||
|
||||
// 拉取最新镜像
|
||||
sh 'docker compose pull'
|
||||
|
||||
// 停止旧容器
|
||||
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"
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user