fbpx

Elastigroup Jenkins Plugin for Google Cloud Platform Preemptible VMs

Scale Your Jenkins Slaves Efficiently And Save Up To 80% Off Jenkins Infrastructure Costs on GCP

Stav Maor
Product Manager

Jenkins supports the Master/Slave mode, where the workload of building projects are delegated to multiple slave nodes, allowing a single Jenkins installation to host a large number of projects, or to provide different environments needed for builds/tests. This blog post describes the Master/Slave mode and how to use it.

We Are Happy To Introduce The New Spotinst’s Elastigroup Google Cloud Platform Preemptible VMs Jenkins Plugin

Spotinst’s Jenkins Plugin helps you to do more with your Jenkins setup by allowing you to automatically configure and scale a designated Google Compute Engine Preemptible VM as Slaves up and down depending on the number of jobs to be completed.
By leveraging Spotinst’s Plugin you have access to these resources with 100% uptime and 70% cost savings.

How It Works

 

Elastigroup Jenkins Flow (3)Spotinst’s Jenkins Plugin automatically scales instances up and down based on the number of jobs in its queue. The nodes that are being provisioned run a startup script and connect as Slave nodes to the Master and immediately start run jobs.

How To Get Started

1. Generate a Spotinst API Access Token

Login into your Spotinst Console and then go to Settings -> Personal Access Tokens ->Generate

Screen Shot 2016-06-05 at 4.51.48 PM

Once you have generated the API Access Token, copy and save it for later use inside the Jenkins Console.

Screen Shot 2016-06-05 at 4.52.01 PM

2. Create an Elastigroup with a Proper Startup Script

Now, create an Elastigroup with your proper Zone, Image, Instance Types and the following startup script

  • #!/bin/bash
  • install_deps() {
  • log_info “Installing dependencies”
  • # Install deps.
  • packages=$1
  • for package in $packages; do
  • installed=$(which $package)
  • not_found=$(echo `expr index “$installed” “no $package in”`)
  • if [ -z $installed ] && [ “$not_found” == “0” ]; then
  • log_info “Installing $package”
  • if [ -f /etc/redhat-release ] || [ -f /etc/system-release ]; then
  • yum install -y $package
  • elif [ -f /etc/arch-release ]; then
  • pacman install -y $package
  • elif [ -f /etc/gentoo-release ]; then
  • emerge install -y $package
  • elif [ -f /etc/SuSE-release ]; then
  • zypp install -y $package
  • elif [ -f /etc/debian_version ]; then
  • apt-get install -y $package
  • fi
  • log_info “$package successfully installed”
  • fi
  • done
  • }
  • INSTANCE_ID=“`curl http://169.254.169.254/latest/meta-data/instance-id`”
  • JENKINS_MASTER_IP=“IP:PORT”
  • # Install Java If not already installed
  • install_deps “jre”
  • # Get The Jenkins Slave JAR file
  • curl http://${JENKINS_MASTER_IP}/jnlpJars/slave.jar –output /tmp/slave.jar
  • # Run the Jenkins Slave JAR
  • java -jar /tmp/slave.jar -jnlpUrl http://${JENKINS_MASTER_IP}/computer/${INSTANCE_ID}/slave-agent.jnlp &

We recommend to use a Linux CentOS Image

3. Install Spotinst’s Jenkins Plugin and Add Your Spotinst API Token and Elastigroup ID

Login into your Jenkins console, and install the Spotinst Plugin from the available Plugins list
Once you have installed the plugin, navigate to the main "Manage Jenkins" > "Configure System" page, and scroll down to the Spotinst Section. Next, add the API Token you’ve generated in the previous step. Then click on "Validate Token", make sure that the token is valid.

 

IMG_2016-08-31 14:51:00

Once you’ve set the Spotinst Token, scroll down near the bottom to the Cloud section and click on the "Add a new cloud" button. Then, select the "Spotinst" option.
Now, you should Specify your "Elastigroup ID" and "Idle minutes before termination"

 

IMG_2016-08-31 14:51:09

You should be all set up to take advantage of the Spotinst Jenkins Plugin! The Jenkins Master will automatically launch new instances through the Spotinst API, and will terminate the instances as they get unused.

 

Best Regards,
The Spotinst Team.

Stav Maor
Product Manager

Stay current

Sign up for our newsletter, and we'll send you the latest updates on Spotinst, tips, tutorials and more cool stuff!