代码拉取完成,页面将自动刷新
同步操作将从 Anyon/wechat-php-sdk 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pipeline {
agent any
environment {
mvnwithjdk8 = '/usr/local/maven/bin/mvn'
backupScript = '/data/jenkins/script'
killport = '/data/app/jenkins-deploy/script/killport.sh'
server1ip = '172.16.0.40'
server2ip = '172.16.4.40'
sship = '112.80.18.246'
devip = '192.168.1.110'
testip = '192.168.1.23'
qaip = '192.168.1.24'
uatip = '192.168.1.100'
serverport = '8185' //服务的端口号
jenkinstemptransfer = '/data/app/jenkins-temp-transfer'
jarpath = '/data/app/jenkins-deploy/tomcat-site-api' //服务的路径
jarname = 'gpyh-site-api-1.0.0.jar' //服务安装包名称
project_name = 'gpyh-site-api' //项目名称
sleeptime = '30' //服务启动后间隔多少秒后去检测
version_number = readMavenPom().getVersion() //pom版本号
opentelemetry_name = '/usr/local/lib/open-telemetry/javaagent/opentelemetry-javaagent-all.jar' //通用配置文件路径
}
stages {
stage('构建') {
steps {
sh '''case $type in
deploy)
echo "type: $type"
$mvnwithjdk8 clean
$mvnwithjdk8 package -P $environment -Dmaven.test.skip=true
;;
rollback)
echo "type: $type"
echo "version: $version"
rm -rf target
cp -R ${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${version}/archive/target .
pwd && ls
;;
*)
exit
;;
esac'''
}
}
stage('备份') {
steps {
archiveArtifacts artifacts: 'target/'
}
}
stage('发布') {
steps{
script{
echo "$environment"
if ("${environment}" == "dev") {
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "ssh yunwei@$devip '$killport $serverport ' ", execTimeout: 120000)], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "scp $jenkinstemptransfer/$jarname yunwei@$devip:$jenkinstemptransfer ; rm $jenkinstemptransfer/$jarname ; ssh yunwei@$devip 'mkdir -p $jarpath ; mv $jenkinstemptransfer/$jarname $jarpath ; source /etc/profile ; nohup java -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ' ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "sleep 30s ; ssh yunwei@$devip 'tail -n 200 $jarpath/nohup.out ' ", execTimeout: 120000)], verbose: true)]
for (i=0; i<30; i++) {
devport = sh (script: "ssh -p 2222 $sship ssh yunwei@$devip netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
echo "$devport"
if ("${devport}" == "$serverport" ) {
echo "jenkins检查服务启动状态,服务已启动成功"
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${devport}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
else if ("${environment}" == "test"){
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "ssh yunwei@$testip '$killport $serverport ' ", execTimeout: 120000)], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "scp $jenkinstemptransfer/$jarname yunwei@$testip:$jenkinstemptransfer ; rm $jenkinstemptransfer/$jarname ; ssh yunwei@$testip 'mkdir -p $jarpath ; mv $jenkinstemptransfer/$jarname $jarpath ; source /etc/profile ; nohup java -javaagent:$opentelemetry_name -Dotel.resource.attributes=service.name=$project_name,service.version=$version_number,host.name=$testip,deployment.environment=test -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ' ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "sleep 30s ; ssh yunwei@$testip 'tail -n 200 $jarpath/nohup.out ' ", execTimeout: 120000)], verbose: true)]
for (i=0; i<30; i++) {
testport = sh (script: "ssh -p 2222 $sship ssh yunwei@$testip netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
echo "$testport"
if ("${testport}" == "$serverport" ) {
echo "jenkins检查服务启动状态,服务已启动成功"
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${testport}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
else if ("${environment}" == "qa"){
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "ssh yunwei@$qaip '$killport $serverport ' ", execTimeout: 120000)], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "scp $jenkinstemptransfer/$jarname yunwei@$qaip:$jenkinstemptransfer ; rm $jenkinstemptransfer/$jarname ; ssh yunwei@$qaip 'mkdir -p $jarpath ; mv $jenkinstemptransfer/$jarname $jarpath ; source /etc/profile ; nohup java -javaagent:$opentelemetry_name -Dotel.resource.attributes=service.name=$project_name,service.version=$version_number,host.name=$qaip,deployment.environment=test -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ' ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "sleep 30s ; ssh yunwei@$qaip 'tail -n 200 $jarpath/nohup.out ' ", execTimeout: 120000)], verbose: true)]
for (i=0; i<30; i++) {
qaport = sh (script: "ssh -p 2222 $sship ssh yunwei@$qaip netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
echo "$qaport"
if ("${qaport}" == "$serverport" ) {
echo "jenkins检查服务启动状态,服务已启动成功"
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${qaport}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
else if ("${environment}" == "uat"){
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "ssh yunwei@$uatip '$killport $serverport ' ", execTimeout: 120000)], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "scp $jenkinstemptransfer/$jarname yunwei@$uatip:$jenkinstemptransfer ; rm $jenkinstemptransfer/$jarname ; ssh yunwei@$uatip 'mkdir -p $jarpath ; mv $jenkinstemptransfer/$jarname $jarpath ; source /etc/profile ; nohup java -Dproject.name=$project_name -jar $jarpath/$jarname >> $jarpath/nohup.out & ' ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$sship", transfers: [sshTransfer(execCommand: "sleep 30s ; ssh yunwei@$uatip 'tail -n 200 $jarpath/nohup.out ' ", execTimeout: 120000)], verbose: true)]
for (i=0; i<30; i++) {
uatport = sh (script: "ssh -p 2222 $sship ssh yunwei@$uatip netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
echo "$uatport"
if ("${uatport}" == "$serverport" ) {
echo "jenkins检查服务启动状态,服务已启动成功"
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${uatport}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
else if ("${environment}" == "production"){
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 -Xms3g -Xmx3g -Xmn1g -javaagent:$opentelemetry_name -Dotel.resource.attributes=service.name=$project_name,service.version=$version_number,host.name=$server1,deployment.environment=production -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$server1", transfers: [sshTransfer(execCommand: "sleep 30s ; tail -n 200 $jarpath/nohup.out ", execTimeout: 120000)], verbose: true)]
sleep "$sleeptime"
for (i=0; i<30; i++) {
prodport = sh (script: "ssh yunwei@$server1 netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
prodport2 = sh (script: "ssh yunwei@$server1 netstat -tnlp | grep $serverport | awk -F ':' '{print \$2}' | awk -F ' ' '{print \$1}' ",returnStdout:true).trim()
echo "$prodport"
echo "$prodport2"
if ("${prodport2}" == "$serverport" || "${prodport}" == "$serverport" ) {
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 -Xms3g -Xmx3g -Xmn1g -javaagent:$opentelemetry_name -Dotel.resource.attributes=service.name=$project_name,service.version=$version_number,host.name=$server2,deployment.environment=production -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$server2", transfers: [sshTransfer(execCommand: "sleep 30s ; tail -n 200 $jarpath/nohup.out ", execTimeout: 120000)], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$server2", transfers: [sshTransfer(execCommand: "netstat -nlp | grep $serverport | awk -F ':' '{print \$2}' | awk -F ' ' '{print \$1}' ", execTimeout: 120000)], verbose: true)]
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${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 -Xms3g -Xmx3g -Xmn1g -javaagent:$opentelemetry_name -Dotel.resource.attributes=service.name=$project_name,service.version=$version_number,host.name=$server,deployment.environment=production -Dproject.name=$project_name -jar $jarpath/$jarname >>$jarpath/nohup.out & ", execTimeout: 120000, patternSeparator: '[, ]+', removePrefix: 'target', sourceFiles: 'target/*.*ar')], verbose: true)]
sshPublisher publishers: [sshPublisherDesc(configName: "$server", transfers: [sshTransfer(execCommand: "sleep 30s ; tail -n 200 $jarpath/nohup.out ", execTimeout: 120000)], verbose: true)]
sleep "$sleeptime"
for (i=0; i<30; i++) {
prodport = sh (script: "ssh yunwei@$server netstat -tnlp | grep $serverport | awk -F : '{print \$4}' ",returnStdout:true).trim()
prodport2 = sh (script: "ssh yunwei@$server netstat -tnlp | grep $serverport | awk -F ':' '{print \$2}' | awk -F ' ' '{print \$1}' ",returnStdout:true).trim()
echo "$prodport"
echo "$prodport2"
if ("${prodport2}" == "$serverport" || "${prodport}" == "$serverport" ) {
echo "检测到服务启动,执行下一步"
break;
}
else {
echo "Jenkins检查服务启动状态,服务还未启动成功,请耐心等待......"
}
sleep 10
}
if ("${prodport2}" != "$serverport" ) {
echo "服务启动失败,请联系对应服务负责人或运维排查问题"
exit 1
}
}
}
else {
echo "取消"
}
}
}
}
}
post {
success {
script{
if ("${environment}" == "production"){
emailext (
subject: '''jenkins - ${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!''',
body: '''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"
offset="0">
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
本邮件由系统自动发出,无需回复!<br/>
各位同事,大家好,以下为${PROJECT_NAME }项目构建信息</br>
<td><font color="#CC0000">构建结果 - ${BUILD_STATUS}</font></td>
</tr>
<tr>
<td><br />
<b><font color="#0B610B">构建信息</font></b>
<hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td>
<ul>
<li>项目名称 : ${PROJECT_NAME}</li>
<li>构建编号 : 第${BUILD_NUMBER}次构建</li>
<li>触发原因: ${CAUSE}</li>
<li>构建状态: ${BUILD_STATUS}</li>
<li>构建日志: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>构建 Url : <a href="${BUILD_URL}">${BUILD_URL}</a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>''',
to: "loujinhe@gpyh.com wujianong@gpyh.com yanyanyong@gpyh.com"
)
}
}
}
failure {
script {
if ("${environment}" == "production"){
emailext (
subject: '''jenkins - ${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!''',
body: '''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"
offset="0">
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
本邮件由系统自动发出,无需回复!<br/>
各位同事,大家好,以下为${PROJECT_NAME }项目构建信息</br>
<td><font color="#CC0000">构建结果 - ${BUILD_STATUS}</font></td>
</tr>
<tr>
<td><br />
<b><font color="#0B610B">构建信息</font></b>
<hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td>
<ul>
<li>项目名称 : ${PROJECT_NAME}</li>
<li>构建编号 : 第${BUILD_NUMBER}次构建</li>
<li>触发原因: ${CAUSE}</li>
<li>构建状态: ${BUILD_STATUS}</li>
<li>构建日志: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>构建 Url : <a href="${BUILD_URL}">${BUILD_URL}</a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>''',
to: "loujinhe@gpyh.com wujianong@gpyh.com yanyanyong@gpyh.com"
)
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。