From a32a4375bc5be41de40ca0a6c752daa1b410677c Mon Sep 17 00:00:00 2001 From: lzh Date: Mon, 13 Apr 2026 14:44:20 +0800 Subject: [PATCH] =?UTF-8?q?build(ci):=20CI/CD=20=E6=94=AF=E6=8C=81=20relea?= =?UTF-8?q?se/next=20=E9=A2=84=E5=8F=91=E5=B8=83=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- .github/workflows/maven.yml | 60 ++++++++++++++++++------------------- Jenkinsfile | 35 ++++++++++++++++++---- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7c76592..aa21a34 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -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 diff --git a/Jenkinsfile b/Jenkinsfile index ae8fe5f..768d074 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 服务器内网地址) + // 部署配置(默认 Prod,release/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 """