Skip to content

Instantly share code, notes, and snippets.

@ducmeit1
Created November 23, 2019 17:18
Show Gist options
  • Save ducmeit1/1997854b93d187fab286e203e5d63756 to your computer and use it in GitHub Desktop.
Save ducmeit1/1997854b93d187fab286e203e5d63756 to your computer and use it in GitHub Desktop.
Jenkinsfile uses for Jenkins Pipeline
#!/usr/bin/env groovy
node {
//Clean workspace before doing anything
deleteDir()
try {
buildNumber = getCurrentBuildNumber()
dockerImage = "ducmeit1/simple-go-lambda:v${buildNumber}"
//Prepare stage will only checkout the last commit of master branch from remote git repository
stage('Prepare') {
checkout scm
}
//Build stage will build docker image and push to docker registry
stage('Build') {
docker.withRegistry("https://hub.docker.io", "docker-hub-credentials") {
//Build docker image
def image = docker.build("")
//Push to registry
image.push()
}
}
//Deploy stage
stage('Deploy') {
//Get current working directory
wd = pwd()
sh "docker run -v ${wd}:/ --rm --entrypoint cp ${dockerImage} ./build.zip ./build.zip"
//Update aws lambda function code
sh "cd ${wd} && aws lambda update-function-code --function-name simple-go-lambda --region ap-southest-1 --zip-file fileb://build.zip"
}
} catch (exception) {
//Set result = 'FAILED' if any exception occur
currentBuild.result = 'FAILED'
throw exception
}
}
def getCurrentBuildNumber() {
return env.BUILD_NUMBER
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment