Skip to content

Instantly share code, notes, and snippets.

@mweagle
Created May 22, 2016 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweagle/4822c3210d681a06409f9b55ab1626ed to your computer and use it in GitHub Desktop.
Save mweagle/4822c3210d681a06409f9b55ab1626ed to your computer and use it in GitHub Desktop.
Jenkins 2.0 build
node {
def golangExists = fileExists '/home/ec2-user/go'
if (!golangExists) {
stage "Configure Go"
sh('curl -vs -L https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz -o /home/ec2-user/go.linux-amd64.tar.gz')
sh('tar -xzf /home/ec2-user/go.linux-amd64.tar.gz -C /home/ec2-user')
} else {
sh('echo Go installed')
}
withEnv(['GOROOT=/home/ec2-user/go', 'GOPATH=$PWD', 'GOBIN=$PWD/bin','AWS_REGION=us-west-2']) {
stage 'Checkout'
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanBeforeCheckout'],
[$class: 'CleanCheckout'],
[$class: 'WipeWorkspace'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'src/SpartaHelloWorld/']],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/mweagle/SpartaHelloWorld']]])
sh 'echo --------------------------'
sh 'mkdir -pv $PWD/{src,pkg,bin}'
withEnv(['PATH=$PATH:$GOROOT/bin']) {
// Go get https://github.com/tebeka/go2xunit to massage test results
sh('go get -v bitbucket.org/tebeka/go2xunit')
dir('src/SpartaHelloWorld') {
def vendorExists = fileExists '.vendor'
if (vendorExists) {
sh 'echo ./vendor directory found'
} else {
sh 'echo ./vendor directory not found'
stage 'Resolve Dependencies'
sh 'go get -v ./...'
}
stage 'Unit Test'
sh 'go test -v | go2xunit -fail -output go-test.xml'
step([$class: 'JUnitResultArchiver', testResults: 'go-test.xml', allowEmptyResults:true])
stage 'Build'
sh 'go build -o sparta.lambda.amd64'
stage 'Provision'
sh 'echo ./sparta.lambda.amd64 --level info provision --s3Bucket weagle'
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment