Skip to content

Instantly share code, notes, and snippets.

@Enigo
Last active September 16, 2023 13:08
Show Gist options
  • Save Enigo/efa2f4c5f0ec5ba6594e35e9f4850195 to your computer and use it in GitHub Desktop.
Save Enigo/efa2f4c5f0ec5ba6594e35e9f4850195 to your computer and use it in GitHub Desktop.
pipeline {
parameters {
choice(name: 'REGION', choices: ['us-east-1']) // add as per your needs
string(name: 'AMI_ID', defaultValue: '', description: '', trim: true)
}
stages {
stage('Validate pipeline parameters') {
steps {
script {
if (!params.AMI_ID?.trim()) {
error("Can't proceed without AMI_ID")
}
currentBuild.description = "${params.REGION}"
}
}
}
stage('Deploy CloudFormation') {
steps {
script {
def templatePath = "cfn.yaml"
def paramsPath = "${REGION}/params.yaml"
sh "sed -i 's/AMI_ID/${AMI_ID}/g' ${paramsPath}"
withAWS(role: "${JENKINS_ROLE}", roleAccount: "${AWS_ACCOUNT}", region: "${REGION}") {
cfnValidate(file: "${templatePath}")
cfnUpdate(stack: "scylladb", file: "${templatePath}", paramsFile: "${paramsPath}")
}
}
}
}
stage('Upscale Scylla ASG') {
steps {
script {
withAWS(role: "${JENKINS_ROLE}", roleAccount: "${AWS_ACCOUNT}", region: "${REGION}") {
def size = 2
def asg = sh(returnStdout: true, script: "aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?(contains(Tags[?Key==`Type`].Value, `scylladb`))].[AutoScalingGroupName]' --output text").trim()
if (!asg?.trim()) {
error("Scylla ASG is not found!")
}
echo "Upscaling Scylla ASG ${asg} to ${size}"
sh "aws autoscaling update-auto-scaling-group --auto-scaling-group-name ${asg} --min-size ${size} --max-size ${size} --desired-capacity ${size}"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment