From 3c7cbd11ad564caf1fcacf6623a468cdf019f611 Mon Sep 17 00:00:00 2001 From: zhouxiunai <154707516@qq.com> Date: Wed, 7 Nov 2018 10:58:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9jenkinsfile=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index f4d57ba..22d0171 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,4 +1,12 @@ node { + def mailto="601470458@qq.com,505127606@qq.com,154707516@qq.com,444949396@qq.com,714943302@qq.com" //邮件接收人员列表 + def containerName="adminweb" //容器名称 + def imageName="130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT" //镜像名称 + def dockerRegistry="http://130.120.3.193" + def credentialsId="e41b57a4-436a-4617-817c-9e3f25a8a47f" //ssh证书id + def deployHost="130.120.3.231" //发布到的主机 + + checkout scm docker.image('teracy/angular-cli').inside() { stage('build'){ @@ -9,10 +17,9 @@ node { } - def imagesName = '130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT' stage('Image Build And Push'){ - docker.withRegistry('http://130.120.3.193', 'privateDockerId') { - docker.build(imagesName).push() + docker.withRegistry("${dockerRegistry}", 'privateDockerId') { + docker.build("${imageName}").push() } } @@ -21,17 +28,17 @@ node { stage('deploy'){ def remote = [:] remote.name = "airport-dev" - remote.host = "130.120.3.231" + remote.host = "${deployHost}" remote.allowAnyHosts = true - withCredentials([sshUserPrivateKey(credentialsId: 'e41b57a4-436a-4617-817c-9e3f25a8a47f', keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) { + withCredentials([sshUserPrivateKey(credentialsId: "${credentialsId}", keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) { remote.user = userName remote.identityFile = kfIdentity - sshCommand remote: remote, command: "docker stop adminweb",sudo: true ,failOnError: false - sshCommand remote: remote, command: "docker rm adminweb",sudo: true ,failOnError: false - sshCommand remote: remote, command: "docker rmi 130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT",sudo: true ,failOnError: false - sshCommand remote: remote, command: "docker run -d -p 96:80 --name adminweb 130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT",sudo: true + sshCommand remote: remote, command: "docker stop ${containerName}",sudo: true ,failOnError: false + sshCommand remote: remote, command: "docker rm ${containerName}",sudo: true ,failOnError: false + sshCommand remote: remote, command: "docker rmi ${imageName}",sudo: true ,failOnError: false + sshCommand remote: remote, command: "docker run -d -p 96:80 --name ${containerName} ${imageName}",sudo: true } } } \ No newline at end of file