From 663846b1a9d801c2d71558d2ae001eaffdfc4e03 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 31 Aug 2018 19:25:22 -0500 Subject: [PATCH] Add Jenkinsfile --- Jenkinsfile | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..f0eb6e5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,56 @@ +def remote = [:] +remote.name = 'budget' +remote.host = 'budget.wbrawner.com' +remote.user = 'root' +remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa' +remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts' + +pipeline { + agent any + stages { + stage('Build') { + steps { + checkout scm + sh 'npm install' + sh 'ng build --prod --aot' + } + } + stage('Prepare Archive') { + steps { + sh 'zip -j archive.zip dist/budget/*' + } + } + stage('Deploy to Production') { + when { + expression { + env.BRANCH_NAME == 'master' + } + } + steps { + sshPut remote: remote, from: 'archive.zip', into: '.' + sshCommand remote: remote, command: """ + mkdir -p /var/www/revisions/$GIT_COMMIT && \ + unzip -d /var/www/revisions/$GIT_COMMIT /root/archive.zip && \ + rm /root/archive.zip && \ + if [ test -L /var/www/html ]; then unlink /var/www/html; fi && \ + ln -s /var/www/revisions/$GIT_COMMIT /var/www/html && \ + if [ \$(ls /var/www/revisions | wc -l) -gt 5 ]; then ls -t /var/www/revisions | tail -n +5 | xargs rm -rf; fi + """ + } + } + stage('Deploy to Dev') { + steps { + sh 'rm /var/www/html/*' + sh 'cp dist/budget/* /var/www/html/' + } + } + } + post { + always { + archiveArtifacts artifacts: 'archive.zip', fingerprint: true + } + cleanup { + cleanWs() + } + } +}