From 9d704d505cd52ec8f7d308666daf331e3455e571 Mon Sep 17 00:00:00 2001 From: bandesz Date: Mon, 27 Feb 2017 10:19:56 +0000 Subject: [PATCH] Add Jenkinsfile for separate deployment --- Jenkinsfile-deploy | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Jenkinsfile-deploy diff --git a/Jenkinsfile-deploy b/Jenkinsfile-deploy new file mode 100644 index 000000000..c1e22f490 --- /dev/null +++ b/Jenkinsfile-deploy @@ -0,0 +1,57 @@ +#!groovy + +node { + try { + stage('Download') { + step([$class: 'WsCleanup']) + + echo "Downloading build artifact.." + withCredentials([ + string(credentialsId: "${aws_env}_aws_access_key", variable: 'AWS_ACCESS_KEY_ID'), + string(credentialsId: "${aws_env}_aws_secret_key", variable: 'AWS_SECRET_ACCESS_KEY') + ]) { + sh 'aws s3 cp --region eu-west-1 s3://${dns_name}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip source.zip' + } + + echo "Extracting build artifact.." + sh 'unzip -q source.zip' + } + stage('Deploy') { + lock(cf_space) { + withCredentials([ + string(credentialsId: 'paas_username', variable: 'CF_USERNAME'), + string(credentialsId: 'paas_password', variable: 'CF_PASSWORD') + ]) { + if (env.CF_APP == 'notify-api-db-migration') { + sh "CF_SPACE=${cf_space} make cf-deploy-api-db-migration-with-docker" + } else { + sh "CF_SPACE=${cf_space} make cf-deploy-with-docker" + } + } + } + } + } catch(err) { + currentBuild.result = 'FAILURE' + echo "PaaS deployment to ${cf_space} failed: ${err}" + try { + slackSend channel: '#govuk-notify', message: "PaaS deployment to ${cf_space} failed: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'danger' + } catch(err2) { + echo "Sending Slack message failed: ${err2}" + } + } finally { + stage('Post-build') { + if (cf_space == 'production') { + try { + slackSend channel: '#govuk-notify', message: "PaaS deployment to ${cf_space} finished: <${env.BUILD_URL}|${env.JOB_NAME} - #${env.BUILD_NUMBER}>", color: 'good' + } catch(err2) { + echo "Sending Slack message failed: ${err2}" + } + } + try { + step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'notify-support+jenkins@digital.cabinet-office.gov.uk', sendToIndividuals: false]) + } catch(err2) { + echo "Sending email failed: ${err2}" + } + } + } +}