build(ci): CI/CD 支持 release/next 预发布分支
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled

- Jenkinsfile: Deploy 和 Health Check 阶段支持 release/next 分支
- release/next 部署到 staging 服务器(172.17.16.7),master 部署到 prod
- 仅 master 分支推送 latest 镜像标签,避免预发布覆盖生产镜像
- GitHub Actions 添加 release/next 分支触发构建

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
lzh
2026-04-13 14:44:20 +08:00
parent 1ca472ea93
commit a32a4375bc
2 changed files with 59 additions and 36 deletions

View File

@@ -1,30 +1,30 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ master ]
# pull_request:
# branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '17' ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.Java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml -Dmaven.test.skip=true
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ master, release/next ]
# pull_request:
# branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '17' ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.Java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml -Dmaven.test.skip=true

35
Jenkinsfile vendored
View File

@@ -27,11 +27,15 @@ pipeline {
// 服务配置
CORE_SERVICES = 'viewsh-gateway,viewsh-module-system-server,viewsh-module-infra-server,viewsh-module-iot-server,viewsh-module-iot-gateway,viewsh-module-ops-server'
// 部署配置Prod 服务器内网地址
// 部署配置(默认 Prodrelease/next 分支会在 Initialize 阶段覆盖为 Staging
DEPLOY_HOST = '172.17.16.14'
DEPLOY_PATH = '/opt/aiot-platform-cloud'
SSH_KEY = '/var/jenkins_home/.ssh/id_rsa'
// Staging 服务器配置
STAGING_DEPLOY_HOST = '172.17.16.7'
STAGING_DEPLOY_PATH = '/opt/aiot-platform-cloud'
// 性能配置 - 将动态调整
BUILD_TIMEOUT = 45
DEPLOY_TIMEOUT = 10
@@ -63,6 +67,15 @@ pipeline {
echo "Start Time: ${new Date()}"
echo "=========================================="
// 根据分支选择部署目标
if (env.BRANCH_NAME == 'release/next') {
env.DEPLOY_HOST = env.STAGING_DEPLOY_HOST
env.DEPLOY_PATH = env.STAGING_DEPLOY_PATH
echo "📦 Deploy target: STAGING (${env.DEPLOY_HOST})"
} else {
echo "📦 Deploy target: PRODUCTION (${env.DEPLOY_HOST})"
}
// 【优化2】动态检测系统资源
detectSystemResources()
}
@@ -261,7 +274,10 @@ pipeline {
when {
allOf {
expression { env.SERVICES_TO_BUILD != '' }
branch 'master'
anyOf {
branch 'master'
branch 'release/next'
}
}
}
steps {
@@ -312,7 +328,10 @@ pipeline {
when {
allOf {
expression { env.SERVICES_TO_BUILD != '' }
branch 'master'
anyOf {
branch 'master'
branch 'release/next'
}
}
}
steps {
@@ -790,12 +809,16 @@ def buildService(String service) {
--build-arg SKIP_TESTS=true \\
--build-arg MAVEN_OPTS="${env.MAVEN_OPTS}" \\
-t ${env.REGISTRY}/${service}:${env.IMAGE_TAG} \\
-t ${env.REGISTRY}/${service}:latest \\
.
# 推送镜像
# 推送带版本号的镜像
docker push ${env.REGISTRY}/${service}:${env.IMAGE_TAG}
docker push ${env.REGISTRY}/${service}:latest
# 仅 master 分支推送 latest 标签
if [ "${env.BRANCH_NAME}" = "master" ]; then
docker tag ${env.REGISTRY}/${service}:${env.IMAGE_TAG} ${env.REGISTRY}/${service}:latest
docker push ${env.REGISTRY}/${service}:latest
fi
set +x
"""