Skip to content

Instantly share code, notes, and snippets.

@mrooney mrooney/deploy_jenkins.sh Secret
Created Jul 11, 2016

Embed
What would you like to do?
#!/usr/bin/env bash
# Usage: ./deploy_jenkins 2.12 [beanstalk_env_name]
set -e
JENKINS_VERSION=$1
BEANSTALK_ENV=$2
JENKINS_WAR_URL="http://mirrors.jenkins-ci.org/war/$JENKINS_VERSION/jenkins.war"
BEANSTALK_APPLICATION="jenkins"
S3_BUCKET="elasticbeanstalk-jenkins-war-versions"
TMP="/tmp"
WAR_NAME="jenkins-$JENKINS_VERSION.war"
WAR_PATH="$TMP/$WAR_NAME"
echo -n "Checking if application version already exists..."
output=$(aws elasticbeanstalk describe-application-versions --application-name=$BEANSTALK_APPLICATION --version-label=$JENKINS_VERSION | grep PROCESSED || true)
if [[ "$output" == "" ]]; then
echo 'false, creating...'
echo "Downloading $JENKINS_WAR_URL => $WAR_PATH..."
curl -sL "$JENKINS_WAR_URL" > $WAR_PATH
echo -n "Ensuring S3 bucket exists... "
aws s3 mb s3://$S3_BUCKET # a no-op if it already exists
echo -n "Uploading war to S3... "
aws s3 cp $WAR_PATH s3://$S3_BUCKET
echo "Creating Elastic Beanstalk Application Version with this war..."
aws elasticbeanstalk create-application-version --auto-create-application --application-name=$BEANSTALK_APPLICATION --version-label=$JENKINS_VERSION --source-bundle=S3Bucket=$S3_BUCKET,S3Key=$WAR_NAME --process
else
echo 'true, skipping.'
fi
if [[ "$BEANSTALK_ENV" != "" ]]; then
eb deploy "$BEANSTALK_ENV" --version "$JENKINS_VERSION"
fi
resource "aws_elastic_beanstalk_application" "jenkins" {
name = "jenkins"
description = "Jenkins CI"
}
resource "aws_elastic_beanstalk_environment" "jenkins-beanstalk" {
name = "jenkins-beanstalk"
application = "${aws_elastic_beanstalk_application.jenkins.name}"
solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Tomcat 8 Java 8"
provisioner "local-exec" {
command = "deploy_jenkins.sh 2.12 jenkins-beanstalk"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.