From c0dfee4bf47c42d137859bef7e2ae08c94e7f43a Mon Sep 17 00:00:00 2001 From: orgin Date: Thu, 11 May 2023 18:41:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:Jenkinsfile=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 85 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a7e45338..c74fbf85 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,25 +1,70 @@ -pipeline { - agent any - stages { - stage('Stop') { - steps { - sh '/var/lib/jenkins/workspace/stop.sh' - } - } - stage('Build') { - steps { - sh 'mvn -B -DskipTests clean install' - } - } - stage('Start'){ - steps { - sh '/var/lib/jenkins/workspace/start.sh' - } - } -// stage('Deploy') { +// pipeline { +// agent any +// stages { +// stage('Stop') { // steps { -// sh 'echo publish' +// sh '/var/lib/jenkins/workspace/stop.sh' // } // } +// stage('Build') { +// steps { +// sh 'mvn -B -DskipTests clean install' +// } +// } +// stage('Start'){ +// steps { +// sh '/var/lib/jenkins/workspace/start.sh' +// } +// } +// // stage('Deploy') { +// // steps { +// // sh 'echo publish' +// // } +// // } +// } +// } + +pipeline { + agent any + + parameters{ + //choice(choices:"master", description:"请填写git分支",name:"branch") + string(defaultValue:"jeecg-system-start-3.5.1.jar", description:"jar包名称",name:"jarName") + string(defaultValue:"alysisSystemForRadionuclide", description:"项目名称",name:"projectName") + string(defaultValue:"/home/zhaohy/test/expect_scp", description:"expect_scp可运行脚本地址",name:"expectScpPath") + string(defaultValue:"/home/zhaohy/test/expect_ssh", description:"expect_ssh可运行脚本地址",name:"expectSsh") + string(defaultValue:"192.168.0.115", description:"scp发送文件的服务器地址",name:"scpHost") + string(defaultValue:"zhaohy", description:"scp发送服务器的用户名",name:"scpUserName") + password(defaultValue:"password", description:"scp发送服务器的密码",name:"scpPwd") + string(defaultValue:"/home/zhaohy/tmp/", description:"scp发送服务器的目标路径",name:"scpTargetPath") } + + + stages() { + stage('打包') { + steps { + sh "pwd" + sh "cd ${params.projectName}/ && mvn clean package -Dmaven.test.skip=true" + } + } + stage('部署') { + steps { + sh "pwd" + sh "cd ${params.projectName}/ && ${params.expectScpPath} ${params.scpHost} ${params.scpUserName} ${params.scpPwd} target/*.jar ${params.scpTargetPath}" + } + } +// stage('备份') { +// steps { +// sh "${params.expectSsh} ${params.scpHost} ${params.scpUserName} ${params.scpPwd} \'cd ${params.scpTargetPath};cp ${params.jarName} backup/${params.projectName}_\$(date +%F-%T).jar\'" +// } +// } + stage('重启') { + steps { + sh "pid=\$(ps -ef|grep $jarName |egrep -v grep|awk '{print \$2}');kill -9 \$pid;nohup java -jar ${params.jarName} >/var/lib/jenkins/workspace/null 2>&1 &\'" +// sh "rm -rf *" + } + } + } + + }