1、在jenkins里新建任务—流水线
2、系统配置—创建Gitlab
3、在app项目里选择刚刚创建的gitlab
4、选择Pipline script,编写pipline脚本
完整代码
#!groovy
pipeline{
agent any
environment{
RESPOSITORY = "git地址库"
MAVEN_HOME = tool "maven"
}
stages {
stage ('拉取代码'){
steps {
echo "开始从 ${RESPOSITORY} 拉取代码..."
// //清空当前目录
// deleteDir()
checkout([$class: 'GitSCM', branches: [[name: '*/分支']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git地址库']]])
echo "代码同步完成"
}
}
stage('编译打包'){
steps {
echo "开始编译"
dir("./"){
sh "${MAVEN_HOME}/bin/mvn clean install -Dmaven.test.skip=true -Ptest"
}
}
}
stage('启动服务'){
parallel {
stage('启动app1服务') {
steps {
//重启服务
dir("app1打包后的路径,项目绝对路径"){
sh "JENKINS_NODE_COOKIE=dontKillMe ./app1.sh"
}
}
}
stage('启动app2服务') {
steps {
//重启服务
dir("app2打包后的路径,项目绝对路径"){
sh "JENKINS_NODE_COOKIE=dontKillMe ./app2.sh"
}
}
}
stage('启动app3服务') {
steps {
//重启服务
dir("app3打包后的路径,项目绝对路径"){
sh "JENKINS_NODE_COOKIE=dontKillMe ./app3.sh"
}
}
}
}
}
}
post {
success {
dingTalk accessToken:'https://oapi.dingtalk.com/robot/send?access_token=***************************************',
imageUrl:'http://webfont.qxsoho.cn/success.png',
jenkinsUrl:'http://localhost/jenkins/',
message:'更新提示: app1部署成功!!!',
notifyPeople:''
}
failure {
dingTalk accessToken:'https://oapi.dingtalk.com/robot/send?access_token=********************************',
imageUrl:'http://webfont.qxsoho.cn/failure.png',
jenkinsUrl:'http://localhost/jenkins/',
message:'更新提示: app1部署失败!!!',
notifyPeople:''
}
}
}