if (userMap['password'].toString() == PASSWORD) {
echo '密码正确'
if (DEPLOY_FLAG == 'deploy') {
echo "发版"
sh "ssh test 'cd /data/faban && sh ${deployMap[env.JOB_NAME]} ${proMap[PROJECT]}'"
}else if (DEPLOY_FLAG == 'predeploy') {
echo '预发布'
sh "ssh test 'cd /data/faban/pre-release && sh ${predeployMap[env.JOB_NAME]} ${proMap[PROJECT]}'"
}else if (DEPLOY_FLAG == 'rollback') {
echo '回滚'
sh "ssh test 'cd /data/faban && sh ${rollbackMap[env.JOB_NAME]} ${proMap[PROJECT]}'"
}
}else {
echo '密码错误'
echo "${env.JOB_NAME}"
}
}
}
}
}
}
post {
always {
echo 'This will always run'
//发版结束后删除jenkins workspace下的临时目录
deleteDir()
}
success {
echo 'This task is successful!'
//记录日志信息
sh """
printf '%s %s %s %s %s %s' `date +'%F %H:%M:%S'` "${env.JOB_NAME}" "${proMap[PROJECT]}" "${DEPLOY_FLAG}" "success!\n" >> /srv/jk_logs/jk.log
"""
}
}
}
五,用到的shell脚本
1, 上传war包的脚本 /srv/shell/TEST_scp_pipe.sh
#!/bin/bash
scp -r /srv/jenkins/workspace/test/test/api/target/api.war test:/data/faban/server_war/risk_api.war
scp -r /srv/jenkins/workspace/test/test/report/target/report.war test:/data/faban/server_war/risk_report.war
scp -r /srv/jenkins/workspace/test/test/job/target/job.war test:/data/faban/server_war/risk_job.war
2, 发版脚本(跳板机)
#!/bin/bash
project="$1"
Java_config=/data/faban/java_config
war_rebuild=/data/faban/war_rebuild
if [ $# -lt 1 ]; then
echo "usage: $0 <project>"
exit 1
fi
case "$project" in
test_api)
tomcat=/opt/tomcat_api
server="test"
;;
test_report)
tomcat=/opt/tomcat_report
server="test"
;;
test_job)
tomcat=/opt/tomcat_job
server="test"
;;
esac
rm -rf $war_rebuild/*
rsync -av /data/faban/server_war/$project.war /data/faban/war_rebuild
cd $war_rebuild