From 33daa2864b490b1096cad002d9867b9fc091ac8c Mon Sep 17 00:00:00 2001 From: wangyuhang <> Date: Mon, 2 Mar 2026 12:38:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84es=E8=BF=9B=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 10244 bytes docker-swarm/elasticsearch/docker-compose.yml | 8 +- docker-swarm/nacos-cluser/pipeline {.groovy | 186 ++++++++++++++++++ 3 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 docker-swarm/nacos-cluser/pipeline {.groovy diff --git a/.DS_Store b/.DS_Store index 460766204ce5ff9d77038a62062d4dc8a168421e..25cf644c6e366d735e94807ec93b4ec72914592a 100644 GIT binary patch literal 10244 zcmeHNU2GIp6h3EKU}k7xfC8NjKSMVH+5+1a8VUkSw_!GhKB>q2`s0lvsV4^~NA@M~c@h=2X6JPYfC{IS^MWg4=oh`8Z#TZ1BnP%>p zd+#}O=X~>>xjAPG0N9q-8v!%`5b0!6siNiv2b*W-b%zj)NFlgqFT5eN|o5tu@NeIGPBnT!W=l1u;7L5-gRkgTL( z|DbEi1AH4TknuoHa_O7WJ$d$kfhh(l26A(n*O)rVcpxXalSBRBkux^*fH0E?uY6yG)~)RB95A?WIiH$oU4QZjj2JLDSZq zVw;nA8%@DiZy8KTAL;swDDGUy|%e!VnPz<)RxA&*^+xK7SX_=-tI$-73cL3(DvXeVtloy+dj zJ?5E??d~#iF3D&-#$Az4Rn1>qx4b^KZo`(u_O71u)w5<(>2qU(Ql`+hBOCt>HLC)wbg1wT~wOlidPIpB`OZ()8@gv=^ggh zSfXn39-SU=r=zn~bWwRt@@Jx|rtW4liJU>LE{gu}3iV#O-z9fNCB+pR*Jts#`>;s~y-J&?mZn#y~4gGxe z!rBE7_Nru|n0CP=YSXLW3|GDoMKKz`kG~a;Y)u*4*jA=O9jt}>p$CR3sETk5o`Vzc z2AqO3@Bw@TpThsd(D{jC9ZpTjCfn7L& zBe)y);y&DuS+sEs58@Gg3?IiQ@JT$5FW`ciYO;yd^*zK3V=V?2kS;HP*If5e~g z68?(6;bj2@Sy(JA6*OU)P$$$2F@Z{f><~&3G{XC(R%oNETYe@ef`ZS4kiAg^MLM?0 z+wW=weO2Yh%-nf3^OrWgKK=QX}%B#ii)F z5?4IV1}FxMLn0%xG9%DlRwq&nDAR)O@)gwGp-ku9NPUAy@umoVSB}IQC5kGgBIwqy zqb~A}+`2)c_);o^?&d8L3wZ_nek4+#pga8o>YjwR;WV6ub41;5;XC*NE)!ivqH8TK z@hKa{dvGOAvvVn^Q&j8DUbR1-E)oA<+aGJk$D3oVY)fpt#rF72 zfK@5D%eP0iecseR-OX5O+RvHsO_j>P5{`fN=r3hs{29VFL?A>UL?A>UL?A@qE+bIE z*VkD6zvJe=|KH`O43`fP2oboG2w-J|lD6T>2)|FcmiL zm*c6!%JD0Mv7mbdfW changed_files.txt + """ + + def diff = readFile('changed_files.txt').trim() + if (!diff) { + echo "✅ 无代码变更,跳过扫描" + currentBuild.result = 'SUCCESS' + return + } + + env.CHANGED_FILES = diff + echo "变更文件:\\n${env.CHANGED_FILES}" + } + } + } + + /* --------------------------------------------------- + * 3. 解析 Gradle 增量模块 + * --------------------------------------------------- */ + stage('Gradle 增量编译') { + tools { + jdk "java17" + gradle 'gradle' + } + steps { + script { + def modules = sh( + script: ''' + awk -F/ ' + { + if (NF >= 2) { + module=":"$1 + for (i=2; i<=NF-1; i++) { + if ($i == "src") break + module=module":"$i + } + print module + } + }' changed_files.txt | sort -u + ''', + returnStdout: true + ).trim() + + if (!modules) { + modules = ":classes" + } + + echo "✅ 受影响模块:\\n${modules}" + + def tasks = modules + .split("\\n") + .collect { "${it}:classes" } + .join(" ") + + sh """ + gradle ${tasks} \ + -x test \ + --parallel \ + --build-cache \ + --configure-on-demand + """ + } + } + } + + /* --------------------------------------------------- + * 4. SonarQube 社区版【增量扫描】 + * --------------------------------------------------- */ + stage('SonarQube 增量扫描(社区版)') { + tools { + jdk "java17" + gradle 'gradle' + } + steps { + script { + + // 仅扫描 src/main/java 下的变更 Java 文件 + def sonarIncludes = sh( + script: ''' + grep -E "src/main/java/.*\\.java$" changed_files.txt \ + | sed 's#^#./#' \ + | tr '\\n' ',' + ''', + returnStdout: true + ).trim() + + if (!sonarIncludes) { + echo "✅ 无 Java 代码变更,跳过 Sonar" + return + } + + echo "Sonar 增量扫描文件:\\n${sonarIncludes}" + + withSonarQubeEnv('sonar-server') { + sh """ + gradle sonar \ + -Dsonar.projectKey=${REPO_NAME} \ + -Dsonar.inclusions=${sonarIncludes} \ + -Dsonar.sourceEncoding=UTF-8 \ + -Dsonar.gradle.skipCompile=true \ + -Dsonar.exclusions=**/* + """ + } + } + } + } + + /* --------------------------------------------------- + * 5. 质量门禁 + PR 反馈 + * --------------------------------------------------- */ + stage('反馈审查结果') { + steps { + script { + def report = waitForQualityGate() + + if (report.status != 'OK') { + sh """ + curl -X POST \ + "https://git.sino-assist.com/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${PR_ID}/comments" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ + "body": "❌ SonarQube 社区版增量扫描未通过\\n\\n📊 报告:${report.dashboardUrl}" + }' + """ + error "❌ 质量门禁失败" + } else { + sh """ + curl -X POST \ + "https://git.sino-assist.com/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/statuses/${GIT_COMMIT}" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ + "context": "sonarqube-check", + "state": "success", + "description": "✅ 社区版增量扫描通过" + }' + """ + } + } + } + } + } +} \ No newline at end of file