Ver Fonte

first commit

alair há 4 meses atrás
commit
19c651fb62
4 ficheiros alterados com 90 adições e 0 exclusões
  1. 58 0
      Jenkinsfile-admin
  2. 32 0
      Jenkinsfile-ui
  3. 0 0
      ruoyi-admin-deploy.yaml
  4. 0 0
      ruoyi-ui-deploy.yaml

+ 58 - 0
Jenkinsfile-admin

@@ -0,0 +1,58 @@
+// 所有的脚本命令都放在pipeline中
+pipeline{
+	// 指定任务的构建在哪个集群节点中执行,any指任意一个
+	agent any
+	// 声明全局变量,方便后面使用
+	environment {
+        harbor_user = 'admin'
+        harbor_passwd = 'Zq0034bgns.'
+        harbor_address = '192.168.0.5:9080'
+        harbor_repo = 'repo'
+	}
+    stages {
+        stage('拉取git仓库代码') {
+            steps {
+                checkout scmGit(branches: [[name: 'origin/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'ef3dc13b-dfb3-4c7a-932d-af43fd8e0fa0', url: 'http://192.168.0.5:13000/Ruoyi/RuoYi-Ademin.git']])
+            }
+        }
+        stage('通过maven构建项目') {
+            steps {
+                sh '/var/jenkins_home/apache-maven-3.9.11/bin/mvn clean package -DskipTests'
+            }
+        }
+        stage('通过SonerQube做代码质量检测') {
+            steps {
+                sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.sources=./ -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.java.binaries=./target/ -Dsonar.token=squ_b5fe8ff602839ce1b3374e2716a1741e62777e79'
+            }
+        }
+        stage('通过Docker制作自定义镜像') {
+            steps {
+                sh '''mv ./target/*.jar ./docker/
+                docker build -t ${JOB_NAME}:latest ./docker/'''
+            }
+        }
+        stage('将自定义镜像推送到Harbor') {
+            steps {
+                sh '''docker login -u ${harbor_user} -p ${harbor_passwd} ${harbor_address}
+                docker tag ${JOB_NAME}:latest ${harbor_address}/${harbor_repo}/${JOB_NAME}:latest
+                docker push ${harbor_address}/${harbor_repo}/${JOB_NAME}:latest'''
+            }
+        }
+        stage('将yaml文件传到k8smaster服务器') {
+            steps {
+                sshPublisher(publishers: [sshPublisherDesc(configName: '应用服务器', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'ruoyi-admin-deploy.yaml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
+            }
+        }
+        stage('远程执行k8s-master的kubectl命令') {
+            steps {
+                sh '''ssh root@192.168.0.3 kubectl apply -f ruoyi-admin-deploy.yaml
+                ssh root@192.168.0.3 kubectl rollout restart deployment ruoyi -n ruoyi'''
+            }
+        }
+        stage('通过npm构建前端项目') {
+            steps {
+                sh '/var/jenkins_home/apache-maven-3.9.11/bin/mvn clean package -DskipTests'
+            }
+        }
+    }
+}

+ 32 - 0
Jenkinsfile-ui

@@ -0,0 +1,32 @@
+// 所有的脚本命令都放在pipeline中
+pipeline{
+	// 指定任务的构建在哪个集群节点中执行,any指任意一个
+	agent any
+	// 声明全局变量,方便后面使用
+	environment {
+        harbor_user = 'admin'
+        harbor_passwd = 'Zq0034bgns.'
+        harbor_address = '192.168.0.5:9080'
+        harbor_repo = 'repo'
+	}
+    stages {
+        stage('拉取git仓库代码') {
+            steps {
+                checkout scmGit(branches: [[name: 'origin/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'ef3dc13b-dfb3-4c7a-932d-af43fd8e0fa0', url: 'http://192.168.0.5:13000/Ruoyi/RuoYi-UI.git']])
+            }
+        }
+        stage('通过node构建项目') {
+            steps {
+                nodejs('nodejs24.12.0') {
+                    sh '''npm run build:prod'''
+                }
+
+            }
+        }
+        stage('通过SonerQube做代码质量检测') {
+            steps {
+                sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.sources=. -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.token=squ_b5fe8ff602839ce1b3374e2716a1741e62777e79'
+            }
+        }
+    }
+}

+ 0 - 0
ruoyi-admin-deploy.yaml


+ 0 - 0
ruoyi-ui-deploy.yaml