Skip to content
Permalink
7cbe04cb02
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
94 lines (66 sloc) 2.48 KB
node('packer') {
currentBuild.result = "SUCCESS"
stage 'Checkout'
checkout scm
stage 'Appliance build'
echo "My Branch is: ${env.BRANCH_NAME}"
BRANCH_TEST = "${env.BRANCH_NAME}"
if (BRANCH_TEST=="shibboleth-production"){
performBuild("shibboleth")
} else if (BRANCH_TEST=="grouper-production"){
performBuild("grouper")
} else if (BRANCH_TEST=="comanage-production"){
performBuild("comanage")
}
}
def performBuild(String project){
try {
stage 'Cleanup & Setup'
sh "rm -rf output-${project}-*"
sh "bin/remove-${project}.sh"
sh 'rm -rf builds'
sh 'mkdir -p builds'
withCredentials([[$class: 'FileBinding', credentialsId: 'tier-aws-config', variable: 'FILE']]) {
ws {
sh 'mkdir -p ~/.aws'
sh 'cp $FILE ~/.aws/config'
}
}
withCredentials([[$class: 'FileBinding', credentialsId: 'tier-aws-credentials', variable: 'FILE']]) {
ws {
sh 'mkdir -p ~/.aws'
sh 'cp $FILE ~/.aws/credentials'
}
}
stage 'Acquire ansible-playbooks'
sh 'rm -rf ansible-playbooks'
sh 'mkdir -p ansible-playbooks'
dir('ansible-playbooks'){
git([ url: "https://github.internet2.edu/docker/ansible-playbooks.git",
branch: "master", credentialsId: "jenkins-github-access-token" ])
}
stage 'Validate'
sh "/usr/local/bin/packer validate ${project}-appliance.json"
stage 'Build Appliance'
sh "/usr/local/bin/packer build ${project}-appliance.json"
stage 'Sync appliances to S3 bucket'
sh "aws s3 sync builds s3://internet2-tier-appliance-us-west-1"
stage 'Publish results'
sh "bin/perms.sh > results.txt"
slackSend color: 'good', message: "BUILD SUCCESS: Appliance build success. ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL} |Open>)"
slackSend color: 'good', message: readFile('./results.txt')
sh "rm results.txt"
}
catch (err) {
handleError("BUILD ERROR: There was a problem with ${project} Appliance. ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL} |Open>) \n\n ${err}", "${project}-appliance-centos7-xfs")
}
}
def handleError(String message, String appliance_name){
echo "${message}"
currentBuild.setResult("FAILED")
slackSend color: 'danger', message: "${message}"
//step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true])
sh "VBoxManage controlvm ${appliance_name} poweroff"
sh "VboxManage unregistervm ${appliance_name} --delete"
sh 'exit 1'
}