Created
November 4, 2018 12:54
-
-
Save mlabouardy/278c8c88e0461c068c9b42f3e9ad53da to your computer and use it in GitHub Desktop.
CI/CD for Serverless apps with Jenkins
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
def bucket = 'deployment-packages-mlabouardy' | |
def functionName = 'Fibonacci' | |
def region = 'eu-west-3' | |
node('slaves'){ | |
stage('Checkout'){ | |
checkout scm | |
} | |
stage('Test'){ | |
sh 'go get -u github.com/golang/lint/golint' | |
sh 'go get -t ./...' | |
sh 'golint -set_exit_status' | |
sh 'go vet .' | |
sh 'go test .' | |
} | |
stage('Build'){ | |
sh 'GOOS=linux go build -o main main.go' | |
sh "zip ${commitID()}.zip main" | |
} | |
stage('Push'){ | |
sh "aws s3 cp ${commitID()}.zip s3://${bucket}" | |
} | |
stage('Deploy'){ | |
sh "aws lambda update-function-code --function-name ${functionName} \ | |
--s3-bucket ${bucket} \ | |
--s3-key ${commitID()}.zip \ | |
--region ${region}" | |
} | |
if (env.BRANCH_NAME == 'master') { | |
stage('Publish') { | |
def lambdaVersion = sh( | |
script: "aws lambda publish-version --function-name ${functionName} --region ${region} | jq -r '.Version'", | |
returnStdout: true | |
) | |
sh "aws lambda update-alias --function-name ${functionName} --name production --region ${region} --function-version ${lambdaVersion}" | |
} | |
} | |
} | |
def commitID() { | |
sh 'git rev-parse HEAD > .git/commitID' | |
def commitID = readFile('.git/commitID').trim() | |
sh 'rm .git/commitID' | |
commitID | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment