添加文件java_server.pipeline(有兴趣的可自行写脚本,本人自实现功能,未做优化)
def img_tag_current = 'registry.msh.com:5000/'+env.JOB_NAME+':' + env.BUILD_NUMBER
def img_tag_lastest = 'registry.msh.com:5000/'+env.JOB_NAME+':lastest'
def build_parm = '--build-arg spring_active=' + SPRING_ACTIVE +' --build-arg project_name=' + env.JOB_NAME + ' --build-arg server_port='+ SERVER_PORT
def context = "docker container rm -f " +env.JOB_NAME +"n"
context = context + "docker rmi -f " +img_tag_lastest +"n"
context = context + "docker run -d --name "+env.JOB_NAME + " -p "+ SERVER_PORT + ":"+ SERVER_PORT + ' ' +img_tag_lastest
echo context
def sh_getscript = 'cp /opt/script/java' + env.JOB_NAME + '.jar')
println files[0].path
sh 'mv '+ files[0].path +" ./"
sh sh_getscript
}
}
}
stage('build docker image'){
steps{
script {
sh 'docker build '+ build_parm +' -t '+ img_tag_current +' .'
sh 'docker tag '+ img_tag_current +' '+ img_tag_lastest
sh 'docker push '+ img_tag_current
sh 'docker push '+ img_tag_lastest
}
}
}
stage('connect server run'){
steps{
script{
def remote = [:]
remote.name = 'server'
remote.host ='192.168.1.69'
remote.user = 'root'
remote.password ='5523003'
remote.allowAnyHosts= true
writeFile file:'start.sh', text: context
sshscript remote: remote,script: "start.sh"
}
}
}
stage('end clear dirctory'){
steps{
script {
sh 'rm -rf ./*'
}
}
}
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)