diff --git a/Jenkinsfile b/Jenkinsfile index e3e8fb3b9..0591ae84e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,9 +4,71 @@ pipeline { stage('Build') { steps { echo 'Running build automation' - sh './gradlew build --no-daemon' + sh './gradlew build --no-daemon' 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 +}