From 013846fc79b53acb1646d797c6f72872347d33b0 Mon Sep 17 00:00:00 2001 From: Pallavi-creator <74696975+Pallavi-creator@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:29:36 -0400 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e3e8fb3b9..14c4b8553 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,5 +8,67 @@ pipeline { archiveArtifacts artifacts: 'dist/trainSchedule.zip' } } + stage('DeployToStaging') { + when { + branch 'master' + } + steps { + withCredentials([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + sshPublisher( + failOnError: true, + continueOnError: false, + publishers: [ + sshPublisherDesc( + configName: 'staging', + sshCredentials: [ + username: "$USERNAME", + encryptedPassphrase: "$USERPASS" + ], + transfers: [ + sshTransfer( + sourceFiles: 'dist/trainSchedule.zip', + removePrefix: 'dist/', + remoteDirectory: '/tmp', + execCommand: 'sudo /usr/bin/systemctl stop train-schedule && rm -rf /opt/train-schedule/* && unzip /tmp/trainSchedule.zip -d /opt/train-schedule && sudo /usr/bin/systemctl start train-schedule' + ) + ] + ) + ] + ) + } + } + } + stage('DeployToProduction') { + when { + branch 'master' + } + steps { + input 'Does the staging environment look OK?' + milestone(1) + withCredentials([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + sshPublisher( + failOnError: true, + continueOnError: false, + publishers: [ + sshPublisherDesc( + configName: 'production', + sshCredentials: [ + username: "$USERNAME", + encryptedPassphrase: "$USERPASS" + ], + transfers: [ + sshTransfer( + sourceFiles: 'dist/trainSchedule.zip', + removePrefix: 'dist/', + remoteDirectory: '/tmp', + execCommand: 'sudo /usr/bin/systemctl stop train-schedule && rm -rf /opt/train-schedule/* && unzip /tmp/trainSchedule.zip -d /opt/train-schedule && sudo /usr/bin/systemctl start train-schedule' + ) + ] + ) + ] + ) + } + } + } } -} \ No newline at end of file +}