代码拉取完成,页面将自动刷新
同步操作将从 盛宇/jenkins_maven 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pipeline {
agent any
environment {
mvnwithjdk8 = '/usr/local/maven/bin/mvn'
killport = '/home/zw/script/kill.sh'
serverport = '1111'
jenkinstemptransfer = '/home/zw/jenkins-temp-transfer'
jarpath = '/home/zw/deploy'
jarname = 'example-0.0.1-SNAPSHOT.jar'
project_name = 'example-SNAPSHOT'
sleeptime = '30'
}
stages {
stage('构建') {
steps {
script{
sh '''
echo "type: $type"
$mvnwithjdk8 clean
$mvnwithjdk8 package
'''
}
}
}
stage('备份') {
steps {
archiveArtifacts artifacts: 'target/'
}
}
stage('发布') {
steps {
script{
echo "环境为:$environment 分支为:$branch"
if ("$server" == "all") {
sshPublisher(publishers: [sshPublisherDesc(configName: "$server1", transfers: [sshTransfer(execCommand: "$killport $serverport", execTimeout: 120000)], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server1", transfers: [sshTransfer(execCommand: "mkdir -p $jenkinstemptransfer; mkdir -p $jarpath; mv $jenkinstemptransfer/$jarname $jarpath; source /etc/profile; nohup java -Dproject.name=$server1 -jar $jarpath/$jarname --server.port=1111 >> $jarpath/nohup.out &", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target/', sourceFiles: 'target/*.*jar')], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server1", transfers: [sshTransfer(execCommand: "tail -n 50 $jarpath/nohup.out", execTimeout: 120000)], verbose: true)])
sleep 5
for (i=0; i<10; i++) {
prodport = sh (script: "ssh zw@$server1 netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
prodport2 = sh (script: "ssh zw@$server1 netstat -tnlp | grep $serverport | awk -F ':' '{print \$2}' | awk -F ' ' '{print \$1}' ",returnStdout:true).trim()
echo "端口为 $prodport $prodport2"
echo "$prodport"
echo "$prodport2"
if ("${prodport}" == "$serverport" || "${prodport2}" == "$serverport") {
echo "检测到服务端口启动,服务运行成功,下面进行健康状态检查"
for (i=0; i<10; i++) {
status = sh (script: "curl -s --connect-timeout 2 -m 2 http://${server1}:1111/",returnStdout:true,returnStatus:true)
// status = sh (script: "curl -s --connect-timeout 2 -m 2 https://back.gpyh.com/healthCheck.html | grep 'success'",returnStdout:true,returnStatus:true)
echo "***************"
echo "result $status"
if ("${status}" == "0") {
echo "服务健康状态检查正常,可以继续部署!正在部署第二台"
sshPublisher(publishers: [sshPublisherDesc(configName: "$server2", transfers: [sshTransfer(execCommand: "$killport $serverport", execTimeout: 120000)], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server2", transfers: [sshTransfer(execCommand: "mkdir -p $jenkinstemptransfer; mkdir -p $jarpath; mv $jenkinstemptransfer/$jarname $jarpath; source /etc/profile; nohup java -Dproject.name=$server2 -jar $jarpath/$jarname --server.port=1111 >> $jarpath/nohup.out &", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target/', sourceFiles: 'target/*.*jar')], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server2", transfers: [sshTransfer(execCommand: "tail -n 50 $jarpath/nohup.out", execTimeout: 120000)], verbose: true)])
break
}
else {
echo "服务健康状态检查不正常,正在重新获取健康状态。。。"
}
sleep 3
}
if ("${status}" != "0") {
echo "服务健康状态检查不正常,请等待正常后再继续部署!当前只部署了 $server1"
}
break
}
else {
echo "服务正在启动请等待。。。"
}
sleep 3
}
if ("${prodport}" != "$serverport" && "${prodport2}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
else {
sshPublisher(publishers: [sshPublisherDesc(configName: "$server", transfers: [sshTransfer(execCommand: "$killport $serverport", execTimeout: 120000)], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server", transfers: [sshTransfer(execCommand: "mkdir -p $jenkinstemptransfer; mkdir -p $jarpath; mv $jenkinstemptransfer/$jarname $jarpath; source /etc/profile; nohup java -Dproject.name=test -jar $jarpath/$jarname --server.port=1111 >> $jarpath/nohup.out 2>&1 &", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target/', sourceFiles: 'target/*.*jar')], verbose: true)])
sshPublisher(publishers: [sshPublisherDesc(configName: "$server", transfers: [sshTransfer(execCommand: "tail -n 50 $jarpath/nohup.out", execTimeout: 120000)], verbose: true)])
sleep 5
for (i=0; i<10; i++) {
prodport = sh (script: "ssh zw@$server netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
prodport2 = sh (script: "ssh zw@$server netstat -tnlp | grep $serverport | awk -F ':' '{print \$2}' | awk -F ' ' '{print \$1}' ",returnStdout:true).trim()
echo "端口为"
echo "端口为 $prodport $prodport2"
echo "$prodport"
echo "$prodport2"
if ("${prodport}" == "$serverport" || "${prodport2}" == "$serverport") {
echo "检测到服务端口启动,服务运行成功,下面进行健康状态检查"
for (i=0; i<10; i++) {
status = sh (script: "curl -s --connect-timeout 2 -m 2 http://${server}:1111/",returnStdout:true,returnStatus:true)
// status = sh (script: "curl -s --connect-timeout 2 -m 2 https://back.gpyh.com/healthCheck.html | grep 'success'",returnStdout:true,returnStatus:true)
echo "***************"
echo "result $status"
if ("${status}" == "0") {
echo "服务健康状态检查正常,如果有第二台要部署可以继续部署!"
break
}
else {
echo "服务健康状态检查不正常,正在重新获取健康状态。。。"
}
sleep 3
}
if ("${status}" != "0") {
echo "服务健康状态检查不正常,如果有第二台要部署,请等待正常后再继续部署!"
}
break
}
else {
echo "服务正在启动请等待。。。"
}
sleep 3
}
if ("${prodport}" != "$serverport" && "${prodport2}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。