diff --git a/scripts/kill-ps.sh b/scripts/kill-ps.sh new file mode 100644 index 00000000..3f18bc7d --- /dev/null +++ b/scripts/kill-ps.sh @@ -0,0 +1,66 @@ +AUTH_RESOURCE_NAME=bonus-auth.jar + +tpid=`ps -ef|grep $AUTH_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Stop Process...' +kill -15 $tpid +fi +sleep 5 +tpid=`ps -ef|grep $AUTH_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Kill Process!' +kill -9 $tpid +else +echo 'Stop Success!' +fi + + +GATEWAY_RESOURCE_NAME=bonus-gateway.jar + +tpid=`ps -ef|grep $GATEWAY_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Stop Process...' +kill -15 $tpid +fi +sleep 5 +tpid=`ps -ef|grep $GATEWAY_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Kill Process!' +kill -9 $tpid +else +echo 'Stop Success!' +fi + + +MA_RESOURCE_NAME=bonus-material.jar + +tpid=`ps -ef|grep $MA_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Stop Process...' +kill -15 $tpid +fi +sleep 5 +tpid=`ps -ef|grep $MA_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Kill Process!' +kill -9 $tpid +else +echo 'Stop Success!' +fi + +SYS_RESOURCE_NAME=bonus-system.jar + +tpid=`ps -ef|grep $SYS_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Stop Process...' +kill -15 $tpid +fi +sleep 5 +tpid=`ps -ef|grep $SYS_RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'` +if [ ${tpid} ]; then +echo 'Kill Process!' +kill -9 $tpid +else +echo 'Stop Success!' +fi + diff --git a/scripts/pipeline.sh b/scripts/pipeline.sh new file mode 100644 index 00000000..53c4bc4f --- /dev/null +++ b/scripts/pipeline.sh @@ -0,0 +1,80 @@ +pipeline { + agent any + environment { + // 设置自定义JDK路径,因为每个项目可能需要不同版本的jdk + JAVA_HOME = '/usr/lib/jvm/jdk1.8.0_381' + JOBNAME="${JOB_NAME}" + JENKINS_NODE_COOKIE = "dontKillMe" + #SPRING_PROFILES_ACTIVE = "dev" + } + stages { + stage('Check out') { + steps { + withCredentials([usernamePassword(credentialsId: 'f7070987-9b49-4ae1-af6d-53a3bf26799b', passwordVariable: 'Max@2023', usernameVariable: 'bonus')]) { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/master']], + doGenerateSubmoduleConfigurations: false, + extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '']], + submoduleCfg: [], + userRemoteConfigs: [[url: 'http://192.168.0.56:3000/bonus/Bonus-Cloud-Material.git']] + ]) + } + } + } + stage('Move file') { + steps { + echo 'move file start!' + sh 'chmod 777 ${WORKSPACE}/scripts/*' + // 如果需要拷贝文件,打开并编写以下脚本 + // sh '${WORKSPACE}/scripts/moveFile.sh' + } + } + stage('Build') { + steps { + echo 'build start!' + sh 'env JAVA_HOME=$JAVA_HOME /usr/local/src/apache-maven-3.9.4/bin/mvn clean package' + } + } + stage('Sonar scan') { + steps { + script { + echo 'sonar scan start!' + def scannerHome = tool 'sonar-scanner' + withSonarQubeEnv('sonarqube-server') { + sh "/usr/local/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner " + + "-Dsonar.projectKey=${JOB_NAME} " + + "-Dsonar.projectName=${JOB_NAME} " + + "-Dsonar.sourceEncoding=UTF-8 " + + "-Dsonar.language=java " + + "-Dsonar.projectVersion=1.0 " + + "-Dsonar.sources=. " + + "-Dsonar.java.source=1.8 " + + "-Dsonar.java.target=1.8 " + + "-Dsonar.scm.disabled=true " + + "-Dsonar.exclusions=test/**,node_modules/**,static/**,**/*.js,**/*.html,**/*.css,**/*.jar " + + "-Dsonar.java.binaries=**/target/classes" + } + } + } + } + stage('Deploy') { + steps { + echo 'deploy start!' + sh '''BUILD_ID=DONTKILLME sh ${WORKSPACE}/scripts/deploy.sh''' + } + } + stage('Dingding') { + steps { + echo 'Dingding start!' + script { + def webhookUrl = 'https://oapi.dingtalk.com/robot/send?access_token=eae0af98514a0db9a9a0d5cd8e337d13e7c16cd81d4a90b503e465a573020add' //替换为你自己的钉钉机器人Webhook地址 + def message = "${JOB_NAME} TEST已完成: ${env.BUILD_URL} \n 到Sonarqube查看问题:http://192.168.0.56:9000/dashboard?id=${JOB_NAME} \n 查看新包: http://192.168.0.56/${JOB_NAME}/${BUILD_NUMBER} " + echo "${message}" + sh "curl -H 'Content-Type: application/json' -d '{\"msgtype\": \"text\", \"text\": {\"content\": \"${message}\"}, \"at\": {\"atMobiles\": [\"张三,李四\"], \"isAtAll\": true}}' ${webhookUrl}" + } + } + } + } +} +