|
@@ -0,0 +1,211 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * 预生产(UAT):Checkout → Maven 打包 → 将 jar/lib 拷到 UAT 部署目录并 docker restart。
|
|
|
|
|
+ *
|
|
|
|
|
+ * Jenkins Job:Pipeline script from SCM 时 Script Path 填 docs/jenkins/Jenkinsfile-uat-build-deploy.groovy
|
|
|
|
|
+ *
|
|
|
|
|
+ * 构建分支:在「Build with Parameters」中填写 GIT_BRANCH,默认 uat-20260202;须与 Gitea 远端分支名完全一致(连字符/下划线不要混用)。
|
|
|
|
|
+ */
|
|
|
|
|
+pipeline {
|
|
|
|
|
+ agent any
|
|
|
|
|
+
|
|
|
|
|
+ options {
|
|
|
|
|
+ buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '2'))
|
|
|
|
|
+ timestamps()
|
|
|
|
|
+ timeout(time: 60, unit: 'MINUTES')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ parameters {
|
|
|
|
|
+ string(
|
|
|
|
|
+ name: 'GIT_BRANCH',
|
|
|
|
|
+ defaultValue: 'uat-20260202',
|
|
|
|
|
+ trim: true,
|
|
|
|
|
+ description: '要构建的 Git 分支名,须与远端一致,例如 uat-20260202、main'
|
|
|
|
|
+ )
|
|
|
|
|
+ booleanParam(name: 'FORCE_UPDATE', defaultValue: true, description: '是否强制更新依赖(mvn -U)')
|
|
|
|
|
+ booleanParam(name: 'ALLOW_SNAPSHOTS', defaultValue: true, description: '是否允许 SNAPSHOT 依赖')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ environment {
|
|
|
|
|
+ MAVEN_HOME = tool '3.6.3'
|
|
|
|
|
+ PATH = "${MAVEN_HOME}/bin:${env.PATH}"
|
|
|
|
|
+
|
|
|
|
|
+ GIT_URL = 'http://8.152.195.41:3000/alien/alien_cloud'
|
|
|
|
|
+ GIT_CREDENTIALS = 'zhanghaomimapingzheng'
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stages {
|
|
|
|
|
+ stage('Checkout') {
|
|
|
|
|
+ steps {
|
|
|
|
|
+ script {
|
|
|
|
|
+ def branch = (params.GIT_BRANCH ?: 'uat-20260202').trim()
|
|
|
|
|
+ if (!branch) {
|
|
|
|
|
+ error('GIT_BRANCH 不能为空')
|
|
|
|
|
+ }
|
|
|
|
|
+ env.GIT_BRANCH = branch
|
|
|
|
|
+ echo ">>> 正在拉取代码... 分支: ${env.GIT_BRANCH}"
|
|
|
|
|
+ git branch: "${env.GIT_BRANCH}",
|
|
|
|
|
+ credentialsId: "${env.GIT_CREDENTIALS}",
|
|
|
|
|
+ url: "${env.GIT_URL}"
|
|
|
|
|
+ sh """
|
|
|
|
|
+ set -e
|
|
|
|
|
+ git fetch origin
|
|
|
|
|
+ git reset --hard origin/${env.GIT_BRANCH}
|
|
|
|
|
+ echo ">>> 当前构建使用的提交:"
|
|
|
|
|
+ git log -1 --oneline
|
|
|
|
|
+ git rev-parse HEAD
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stage('Prepare Maven Settings') {
|
|
|
|
|
+ steps {
|
|
|
|
|
+ script {
|
|
|
|
|
+ writeFile file: 'settings.xml', text: """<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
|
|
|
|
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
|
+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
|
|
|
|
+ <profiles>
|
|
|
|
|
+ <profile>
|
|
|
|
|
+ <id>repo-mix</id>
|
|
|
|
|
+ <repositories>
|
|
|
|
|
+ <repository>
|
|
|
|
|
+ <id>central</id>
|
|
|
|
|
+ <name>Maven Central</name>
|
|
|
|
|
+ <url>https://repo.maven.apache.org/maven2</url>
|
|
|
|
|
+ <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </repository>
|
|
|
|
|
+ <repository>
|
|
|
|
|
+ <id>spring-milestones</id>
|
|
|
|
|
+ <name>Spring Milestones</name>
|
|
|
|
|
+ <url>https://repo.spring.io/milestone</url>
|
|
|
|
|
+ <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </repository>
|
|
|
|
|
+ <repository>
|
|
|
|
|
+ <id>spring-snapshots</id>
|
|
|
|
|
+ <name>Spring Snapshots</name>
|
|
|
|
|
+ <url>https://repo.spring.io/snapshot</url>
|
|
|
|
|
+ <releases><enabled>false</enabled></releases>
|
|
|
|
|
+ <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
|
|
|
|
|
+ </repository>
|
|
|
|
|
+ </repositories>
|
|
|
|
|
+ <pluginRepositories>
|
|
|
|
|
+ <pluginRepository>
|
|
|
|
|
+ <id>central</id>
|
|
|
|
|
+ <url>https://repo.maven.apache.org/maven2</url>
|
|
|
|
|
+ <releases><enabled>true</enabled></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </pluginRepository>
|
|
|
|
|
+ <pluginRepository>
|
|
|
|
|
+ <id>spring-milestones</id>
|
|
|
|
|
+ <url>https://repo.spring.io/milestone</url>
|
|
|
|
|
+ <releases><enabled>true</enabled></releases>
|
|
|
|
|
+ <snapshots><enabled>false</enabled></snapshots>
|
|
|
|
|
+ </pluginRepository>
|
|
|
|
|
+ </pluginRepositories>
|
|
|
|
|
+ </profile>
|
|
|
|
|
+ </profiles>
|
|
|
|
|
+ <activeProfiles>
|
|
|
|
|
+ <activeProfile>repo-mix</activeProfile>
|
|
|
|
|
+ </activeProfiles>
|
|
|
|
|
+</settings>
|
|
|
|
|
+"""
|
|
|
|
|
+ }
|
|
|
|
|
+ echo ">>> 已生成 settings.xml(包含 Spring 官方仓库)"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stage('Maven Build') {
|
|
|
|
|
+ steps {
|
|
|
|
|
+ script {
|
|
|
|
|
+ def updateFlag = params.FORCE_UPDATE ? '-U' : ''
|
|
|
|
|
+ echo ">>> 开始 Maven 打包(FORCE_UPDATE=${params.FORCE_UPDATE})"
|
|
|
|
|
+
|
|
|
|
|
+ retry(2) {
|
|
|
|
|
+ sh """
|
|
|
|
|
+ set -e
|
|
|
|
|
+ mvn -version
|
|
|
|
|
+
|
|
|
|
|
+ echo ">>> [1/3] 清理代理环境变量 (防止 HTTP 劫持)..."
|
|
|
|
|
+ unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY all_proxy no_proxy NO_PROXY || true
|
|
|
|
|
+
|
|
|
|
|
+ echo ">>> [2/3] 启用 SSL 证书绕过 (防止证书不匹配)..."
|
|
|
|
|
+ export MAVEN_OPTS="-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true"
|
|
|
|
|
+
|
|
|
|
|
+ echo ">>> [3/3] 清理本地仓库缓存 (防止 404 缓存)..."
|
|
|
|
|
+ rm -rf /root/.m2/repository/org/springframework/cloud/spring-cloud-dependencies/Hoxton.SR1 || true
|
|
|
|
|
+ rm -rf /root/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE || true
|
|
|
|
|
+ rm -rf ${WORKSPACE}/.m2/repository/org/springframework/cloud/spring-cloud-dependencies/Hoxton.SR1 || true
|
|
|
|
|
+ rm -rf ${WORKSPACE}/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE || true
|
|
|
|
|
+
|
|
|
|
|
+ echo ">>> 执行 Maven 打包..."
|
|
|
|
|
+ mvn clean package -DskipTests -s settings.xml ${updateFlag} -e -Dmaven.repo.local=${WORKSPACE}/.m2/repository
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stage('Deploy Services') {
|
|
|
|
|
+ steps {
|
|
|
|
|
+ script {
|
|
|
|
|
+ def services = [
|
|
|
|
|
+ "alien-gateway:gateway-uat",
|
|
|
|
|
+ "alien-job:job-uat",
|
|
|
|
|
+ "alien-lawyer:lawyer-uat",
|
|
|
|
|
+ "alien-second:second-uat",
|
|
|
|
|
+ "alien-store:store-uat",
|
|
|
|
|
+ "alien-dining:dining-uat",
|
|
|
|
|
+ "alien-store-platform:store-platform-uat"
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ for (item in services) {
|
|
|
|
|
+ def (moduleName, dirName) = item.split(':')
|
|
|
|
|
+ def sourceJar = "${env.WORKSPACE}/${moduleName}/target/${moduleName}-1.0.0.jar"
|
|
|
|
|
+ def sourceLib = "${env.WORKSPACE}/${moduleName}/target/lib"
|
|
|
|
|
+ def targetDir = "/app_deploy_uat/${dirName}"
|
|
|
|
|
+
|
|
|
|
|
+ sh """
|
|
|
|
|
+ set -e
|
|
|
|
|
+ echo ">>> 正在处理模块: ${moduleName}"
|
|
|
|
|
+
|
|
|
|
|
+ if [ -f "${sourceJar}" ]; then
|
|
|
|
|
+ mkdir -p "${targetDir}"
|
|
|
|
|
+
|
|
|
|
|
+ if [ -d "${sourceLib}" ]; then
|
|
|
|
|
+ rm -rf "${targetDir}/lib"
|
|
|
|
|
+ cp -rf "${sourceLib}" "${targetDir}"
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ cp -f "${sourceJar}" "${targetDir}/"
|
|
|
|
|
+
|
|
|
|
|
+ if docker ps -a --format '{{.Names}}' | grep -wq "${dirName}"; then
|
|
|
|
|
+ docker restart "${dirName}"
|
|
|
|
|
+ echo ">>> [${dirName}] 重启成功"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo ">>> [${dirName}] 容器不存在,仅完成文件拷贝"
|
|
|
|
|
+ fi
|
|
|
|
|
+ else
|
|
|
|
|
+ echo ">>> [${dirName}] 未发现 Jar 包,跳过"
|
|
|
|
|
+ fi
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ post {
|
|
|
|
|
+ always {
|
|
|
|
|
+ echo ">>> 构建任务结束"
|
|
|
|
|
+ sh "rm -f settings.xml || true"
|
|
|
|
|
+ }
|
|
|
|
|
+ success {
|
|
|
|
|
+ echo ">>> 流水线执行成功"
|
|
|
|
|
+ }
|
|
|
|
|
+ failure {
|
|
|
|
|
+ echo ">>> 流水线执行失败,请检查 Maven 日志中是否仍有 Download 失败"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|