Skip to content

Instantly share code, notes, and snippets.

@cyrille-leclerc
Created September 6, 2017 15:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyrille-leclerc/25e5736e1a2ee1990551459f168f0d0e to your computer and use it in GitHub Desktop.
Save cyrille-leclerc/25e5736e1a2ee1990551459f168f0d0e to your computer and use it in GitHub Desktop.
Jenkinsfile nexus aws beanstalk
#!/usr/bin/env groovy
properties([
buildDiscarder(logRotator(numToKeepStr: '5')),
parameters([string(defaultValue: 'LATEST', name: 'Version', description: 'application version')]),
pipelineTriggers([upstream(upstreamProjects: '/geolocation/atm-by-zip-service-compliance/master', threshold: 'SUCCESS')])
])
def artifactGroupId = "com.beesbank.service"
def artifactArtifactId = "atm-by-zip-service"
def deploymentEnvironment = artifactArtifactId + "-production"
def deploymentUrl = "http://atm-by-zip-service-production.us-east-1.elasticbeanstalk.com/"
node {
stage ('Download') {
deleteDir()
def artifactVersion = Version // "0.0.1-SNAPSHOT"
def repositoryName = artifactVersion.endsWith("-SNAPSHOT") || artifactVersion.equals("LATEST") ? "snapshots" : "releases"
def repositoryUrl = "https://nexus.beescloud.com/content/repositories/$repositoryName/"
sh "wget --no-verbose " +
"\"https://nexus.beescloud.com/service/local/artifact/maven/content?" +
"r=$repositoryName&" +
"g=$artifactGroupId&" +
"a=$artifactArtifactId&" +
"v=$artifactVersion&" +
"p=jar\" " +
"--content-disposition"
}
stage ("Deploy") {
withAwsCli(credentialsId: 'aws', defaultRegion: 'us-east-1') {
// DEPLOY TO BEANSTALK
def destinationJarFile = "$artifactArtifactId-${env.BUILD_NUMBER}.jar"
def versionLabel = "$artifactArtifactId#${env.BUILD_NUMBER}"
def description = "${env.BUILD_URL}"
sh """\
aws s3 cp $artifactArtifactId-*.jar s3://beesbank/$destinationJarFile
aws elasticbeanstalk create-application-version --source-bundle S3Bucket=beesbank,S3Key=$destinationJarFile --application-name $artifactArtifactId --version-label $versionLabel --description \\\"$description\\\"
aws elasticbeanstalk update-environment --environment-name $deploymentEnvironment --application-name $artifactArtifactId --version-label $versionLabel --description \\\"$description\\\"
"""
sleep 10L // wait for beanstalk to update the HealthStatus
// WAIT FOR BEANSTALK DEPLOYMENT
timeout(time: 10, unit: 'MINUTES') {
waitUntil {
sh "aws elasticbeanstalk describe-environment-health --environment-name $deploymentEnvironment --attribute-names All > .beanstalk-status.json"
// parse `describe-environment-health` output
def beanstalkStatusAsJson = readFile(".beanstalk-status.json")
def beanstalkStatus = new groovy.json.JsonSlurper().parseText(beanstalkStatusAsJson)
println "$beanstalkStatus"
return beanstalkStatus.HealthStatus == "Ok" && beanstalkStatus.Status == "Ready"
}
}
hipchatSend color: 'GREEN', message: "Application $artifactArtifactId deployed to production: $deploymentUrl"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment