更新jenkinsfuke
This commit is contained in:
Vendored
+75
-31
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env groovy
|
#!/usr/bin/env groovy
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent { label 'linux' }
|
||||||
parameters {
|
parameters {
|
||||||
choice(name: 'PROJECT_NAME', choices: ['chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen'], description: '请选择发布的项目')
|
choice(name: 'PROJECT_NAME', choices: ['chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen'], description: '请选择发布的项目')
|
||||||
}
|
}
|
||||||
@@ -8,12 +8,20 @@ pipeline {
|
|||||||
jdk 'JDK8'
|
jdk 'JDK8'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
REGISTRY = "192.168.0.19:9011"
|
||||||
|
DEPLOY_USER = "goojia"
|
||||||
|
DEPLOY_HOST = "192.168.0.80" // 目标部署服务器 IP,按实际修改
|
||||||
|
DEPLOY_BASE = "//home/docker/fangjia-coresite" // docker-compose 所在根目录
|
||||||
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage("Git Checkout") {
|
stage("Git Checkout") {
|
||||||
steps {
|
steps {
|
||||||
git changelog: false, credentialsId: 'Gitea_Admin_Token', poll: false, url: 'https://gitea.fangjia.com/dev0/main.git'
|
git changelog: false, credentialsId: 'Gitea_Admin_Token', poll: false, url: 'https://gitea.fangjia.com/dev0/main.git'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Maven Build') {
|
stage('Maven Build') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
@@ -22,7 +30,7 @@ pipeline {
|
|||||||
if (params.PROJECT_NAME == project) {
|
if (params.PROJECT_NAME == project) {
|
||||||
dir("deliverables/${project}") {
|
dir("deliverables/${project}") {
|
||||||
withMaven(globalMavenSettingsConfig: '426b9a25-aa0d-47d3-a24c-8abdfc4421ff') {
|
withMaven(globalMavenSettingsConfig: '426b9a25-aa0d-47d3-a24c-8abdfc4421ff') {
|
||||||
sh 'mvn clean package -Dmaven.test.skip=true'
|
sh 'mvn clean package -Dmaven.test.skip=true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,19 +38,31 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Docker Build') {
|
|
||||||
|
stage('Docker Build & Push') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def projects = ['fangjiabkoff', 'chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen']
|
def projects = ['fangjiabkoff', 'chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen']
|
||||||
def imagesName = ['fangjiabkoff': 'fangjia-bkoff', 'chafangtong': 'chafangtong', 'fangjia': 'fangjia-coresite', 'fangjiapds': 'fangjia-pds', 'fangjiastatic': 'fangjia-static', 'geluke':"geluke", 'fangjiaopen': 'fangjia-open']
|
def imagesName = [
|
||||||
|
'fangjiabkoff' : 'fangjia-bkoff',
|
||||||
|
'chafangtong' : 'chafangtong',
|
||||||
|
'fangjia' : 'fangjia-coresite',
|
||||||
|
'fangjiapds' : 'fangjia-pds',
|
||||||
|
'fangjiastatic' : 'fangjia-static',
|
||||||
|
'geluke' : 'geluke',
|
||||||
|
'fangjiaopen' : 'fangjia-open'
|
||||||
|
]
|
||||||
for (def project : projects) {
|
for (def project : projects) {
|
||||||
if (params.PROJECT_NAME == project) {
|
if (params.PROJECT_NAME == project) {
|
||||||
dir("projects/${imagesName[project]}") {
|
def imageName = imagesName[project]
|
||||||
withDockerRegistry(credentialsId: 'DockerNexus', url: 'http://192.168.0.19:9012') {
|
def imageTag = env.BUILD_TAG.toLowerCase()
|
||||||
sh "docker build -t 192.168.0.19:9011/${imagesName[project]}:${env.BUILD_TAG.toLowerCase()} ."
|
dir("projects/${imageName}") {
|
||||||
withDockerRegistry(credentialsId: 'DockerNexus', url: 'http://192.168.0.19:9011') {
|
withDockerRegistry(credentialsId: 'DockerNexus', url: "http://${REGISTRY}") {
|
||||||
sh "docker push 192.168.0.19:9011/${imagesName[project]}:${env.BUILD_TAG.toLowerCase()}"
|
sh "docker build -t ${REGISTRY}/${imageName}:${imageTag} ."
|
||||||
}
|
sh "docker push ${REGISTRY}/${imageName}:${imageTag}"
|
||||||
|
// 同时打 latest 方便 docker compose pull
|
||||||
|
sh "docker tag ${REGISTRY}/${imageName}:${imageTag} ${REGISTRY}/${imageName}:latest"
|
||||||
|
sh "docker push ${REGISTRY}/${imageName}:latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,26 +70,50 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stage('K8S Deploy') {
|
|
||||||
// steps {
|
stage('Docker Compose Deploy') {
|
||||||
// script {
|
steps {
|
||||||
// def projects = ['fangjiabkoff', 'chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen']
|
script {
|
||||||
// def k8s_config_map = ['fangjiabkoff': 'fangjia-bkoff', 'chafangtong': 'chafangtong', 'fangjia': 'fangjia-coresite', 'fangjiapds': 'fangjia-pds', 'fangjiastatic': 'fangjia-static', 'geluke':"geluke", 'fangjiaopen': 'fangjia-open']
|
def composeDir = [
|
||||||
// for (def project : projects) {
|
'fangjiabkoff' : 'fangjia-bkoff',
|
||||||
// if (params.PROJECT_NAME == project) {
|
'chafangtong' : 'chafangtong',
|
||||||
// dir("deliverables/k8s") {
|
'fangjia' : 'fangjia-coresite',
|
||||||
// withKubeConfig([credentialsId: 'K8SSecret', serverUrl: 'https://k8s.fangjia.com:6443']) {
|
'fangjiapds' : 'fangjia-pds',
|
||||||
// def orgVersion = "${k8s_config_map[project]}:latest"
|
'fangjiastatic' : 'fangjia-static',
|
||||||
// def nowVersion = "${k8s_config_map[project]}:${env.BUILD_TAG.toLowerCase()}"
|
'geluke' : 'geluke',
|
||||||
// sh "sed -i 's/${orgVersion}/${nowVersion}/g' ${k8s_config_map[project]}.yaml"
|
'fangjiaopen' : 'fangjia-open'
|
||||||
// sh "kubectl apply -f ${k8s_config_map[project]}.yaml"
|
]
|
||||||
// }
|
def project = params.PROJECT_NAME
|
||||||
// }
|
def dir = composeDir[project]
|
||||||
// }
|
def imageTag = env.BUILD_TAG.toLowerCase()
|
||||||
// }
|
|
||||||
// }
|
sshagent(['deploy-server']) {
|
||||||
// }
|
sh """
|
||||||
// }
|
ssh -o StrictHostKeyChecking=no ${DEPLOY_USER}@${DEPLOY_HOST} '
|
||||||
|
cd ${DEPLOY_BASE}/${dir}
|
||||||
|
|
||||||
|
# 拉取最新镜像
|
||||||
|
docker compose pull
|
||||||
|
|
||||||
|
# 重启对应服务(不影响其他服务)
|
||||||
|
docker compose up -d --no-deps --force-recreate ${dir}
|
||||||
|
|
||||||
|
# 清理旧镜像
|
||||||
|
docker image prune -f
|
||||||
|
'
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo "✅ ${params.PROJECT_NAME} 部署成功,镜像版本:${env.BUILD_TAG.toLowerCase()}"
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "❌ ${params.PROJECT_NAME} 部署失败,请检查日志"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user