From 562bc25b0f352f4c00987c3f78901303687aca75 Mon Sep 17 00:00:00 2001 From: aaekwal <70737552+aaekwal@users.noreply.github.com> Date: Mon, 22 Mar 2021 03:10:35 -0600 Subject: [PATCH 1/2] Update Jenkinsfile --- Jenkinsfile | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e3e8fb3b..cbc4f13a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,5 +8,52 @@ pipeline { archiveArtifacts artifacts: 'dist/trainSchedule.zip' } } + stage('Build Docker Image') { + when { + branch 'master' + } + steps { + script { + app = docker.build("willbla/train-schedule") + app.inside { + sh 'echo $(curl localhost:8080)' + } + } + } + } + stage('Push Docker Image') { + when { + branch 'master' + } + steps { + script { + docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') { + app.push("${env.BUILD_NUMBER}") + app.push("latest") + } + } + } + } + stage('DeployToProduction') { + when { + branch 'master' + } + steps { + input 'Deploy to Production?' + milestone(1) + withCredentials([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + script { + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker pull willbla/train-schedule:${env.BUILD_NUMBER}\"" + try { + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker stop train-schedule\"" + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker rm train-schedule\"" + } catch (err) { + echo: 'caught error: $err' + } + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker run --restart always --name train-schedule -p 8080:8080 -d willbla/train-schedule:${env.BUILD_NUMBER}\"" + } + } + } + } } -} \ No newline at end of file +} From 0c8bdbc03cf33da3a186dff097abb830ab556da2 Mon Sep 17 00:00:00 2001 From: aaekwal <70737552+aaekwal@users.noreply.github.com> Date: Mon, 22 Mar 2021 03:21:50 -0600 Subject: [PATCH 2/2] Update Jenkinsfile --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cbc4f13a..294a9597 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { } steps { script { - app = docker.build("willbla/train-schedule") + app = docker.build("aaekwal/train-schedule") app.inside { sh 'echo $(curl localhost:8080)' } @@ -41,16 +41,16 @@ pipeline { steps { input 'Deploy to Production?' milestone(1) - withCredentials([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + withCredentials([usernamePassword(credentialsId: 'webserver_id', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { - sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker pull willbla/train-schedule:${env.BUILD_NUMBER}\"" + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker pull aaekwal/train-schedule:${env.BUILD_NUMBER}\"" try { sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker stop train-schedule\"" sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker rm train-schedule\"" } catch (err) { echo: 'caught error: $err' } - sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker run --restart always --name train-schedule -p 8080:8080 -d willbla/train-schedule:${env.BUILD_NUMBER}\"" + sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker run --restart always --name train-schedule -p 8080:8080 -d aaekwal/train-schedule:${env.BUILD_NUMBER}\"" } } }