From 4158ffefe41cec660357344b627955d73ec4cacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A2=E5=BF=97=E9=82=A6?= <775288271@qq.com> Date: Sat, 30 May 2026 10:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Jenkins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkins | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Jenkins diff --git a/Jenkins b/Jenkins new file mode 100644 index 0000000..2badb88 --- /dev/null +++ b/Jenkins @@ -0,0 +1,101 @@ +@Library("devops") _ +def build = new org.devops.Build() +pipeline { + agent {label "build01"} + options { + skipDefaultCheckout true + } + stages { + stage('Checkout') { + steps { + script{ + // 下载代码 + currentBuild.description = "BranchName: ${env.branchName}" + checkout scmGit(branches: [[name: "${env.branchName}"]], + extensions: [], + userRemoteConfigs: [[ + credentialsId: '1f5dd05c-9c82-47da-a96d-79e28bdc2377', + url: "${env.srcUrl}"]]) + } + } + } + stage('Build'){ + steps{ + script{ + //构建阶段 + build.Build() + } + } + } + stage('UniTest'){ + when { + environment name: 'skipUnitTest',value: 'false' + } + steps{ + script{ + // 单元测试 + build.UniTest() + } + } + } + stage('CodeScan'){ + steps{ + script{ + //代码扫描 + + //withCredentials([usernamePassword( + // credentialsId: 'be40ed93-4404-4242-a95b-25ed974be409', + // passwordVariable: 'PASSWORD', + // usernameVariable: 'USERNAME')]) { + // sh "sonar-scanner -Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD}" + //} + withSonarQubeEnv(credentialsId: '4cd3f9f5-d675-4c85-b1c9-54329bed4902') { + sh """ + sonar-scanner -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.projectVersion=${env.branchName} -Dsonar.branch.name=${env.branchName} + """ + } + + } + } + } + stage('PushArtifacts'){ + steps{ + script{ + // 上传制品 + def repoId="devops" + def targetDir="devops/${JOB_NAME}/" + def pkgPath="target" + + def POM = readMavenPom file:'pom.xml' + env.artifactId = "${POM.artifactId}" + env.packaging = "${POM.packaging}" + env.groupId = "${POM.groupId}" + env.art_version = "${POM.version}" + + pkgName = "${env.artifactId}-${env.art_version}.${env.packaging}" + PushNexusArtifact(repoId,targetDir,pkgPath,pkgName) + } + } + } + } +} + +def PushNexusArtifact(repoId,targetDir,pkgPath,pkgName){ + withCredentials([ + usernamePassword( + credentialsId: '4df0140e-023c-4b64-983d-6a2054e74228', + passwordVariable: 'PASSWORD', + usernameVariable: 'USERNAME' + ) + ]) { + sh """ + curl -v -u ${USERNAME}:${PASSWORD} \ + -X POST \ + "http://192.168.0.160:8081/service/rest/v1/components?repository=${repoId}" \ + -H "accept: application/json" \ + -F "raw.directory=${targetDir}" \ + -F "raw.asset1=@${pkgPath}/${pkgName}" \ + -F "raw.asset1.filename=${pkgName}" + """ + } +}