Created
October 20, 2018 18:34
-
-
Save nimboya/b707a4be8e3e65ce65fba454ddf930f2 to your computer and use it in GitHub Desktop.
Sample Jenkins file for Serverless Build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import java.util.Date | |
import groovy.json.JsonOutput | |
import groovy.json.JsonSlurper | |
def displayName = env.JOB_NAME | |
def bucketName = env.JOB_NAME | |
def isMaster = env.BRANCH_NAME == "master" | |
def isStaging = env.BRANCH_NAME == "staging" | |
def start = new Date() | |
def err = null | |
String jobInfoShort = "${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME}" | |
String jobInfo = "${env.JOB_NAME} ${env.BUILD_DISPLAY_NAME} \n${env.BUILD_URL}" | |
String buildStatus | |
currentBuild.result = "SUCCESS" | |
try { | |
node { | |
deleteDir() | |
stage ('Checkout') { | |
checkout scm | |
} | |
// In the interim, run builds only on staging and master | |
if (isStaging || isMaster) { | |
stage('Prepare Environment') { | |
sh "pip3 install --user -r requirements.txt" | |
} | |
stage ("Deploy with Chalice"){ | |
if (isStaging) { | |
sh "export AWS_DEFAULT_REGION=eu-west-1 && chalice deploy --stage staging" | |
} else { | |
sh "export AWS_DEFAULT_REGION=eu-west-1 && chalice deploy --stage production" | |
} | |
slackSend (color: 'good', message: "${response}") // send to slack | |
} | |
} | |
} | |
} catch (caughtError) { | |
err = caughtError | |
currentBuild.result = "FAILURE" | |
slackSend (color: 'danger', message: "_Build failed_: ${jobInfo}") | |
throw err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment