Spotinst raises $15M Series A Led By Intel Capital and Vertex Ventures Read The Official Press Release

UPDATED! Elastigroup Jenkins Plugin

Scale Your Jenkins Salves Efficiently and Save Up to 90% Off Jenkins Infrastructure Costs

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 document describes this mode and how to use it.

We are happy to introduce our new Elastigroup Jenkins Plugin

This plug-in helps you to do more with your Jenkins setup, by allowing you to configure Jenkins to automatically scale a designated Amazon EC2 VMs as Slaves up or down depending on the number jobs to be completed.
Spotinst Plug-in enables you to get these resources with 100% uptime and 80% discount.

How It Works

jenkins-flow-01

The Spotinst Jenkins plug-in automatically scales up&down instances 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 to 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

jenkins-flow-02

Once you’ve generated the API Access Token, Copy it, and save it for later use inside the Jenkins Console.

jenkins-flow-03

2. Create an Elastigroup with a Proper Startup Script

Now, Create an Elastigroup with your proper Region, AMI, 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
}


EC2_INSTANCE_ID="`curl http://instance-data/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/${EC2_INSTANCE_ID}/slave-agent.jnlp &

Use jnlpCredentials flag to the command with your username / password or token (such as the GitHub access token if GitHub is being used to authenticate with Jenkins).

# Run the Jenkins slave JAR
java -jar /tmp/slave.jar -jnlpCredentials user:password/token -jnlpUrl http://${JENKINS_MASTER_IP}/computer/${EC2_INSTANCE_ID}/slave-agent.jnlp &

We recommend to use the Amazon Standard AMI (CentOS based)

3. Change the default slave connection port

By default your slaves will try to connect on a random port. This requires opening your firewall rules to allow all ports to be open to ensure successful communication from slave to master. You can optionally configure a static port for your Jenkins slaves by going into Manage Jenkins >  Global Security > and set a static TCP port for JNLP agents.
jenkins-global-security

 

4. Install the Jenkins Plugin and Add Your Spotinst API Token and Elastigroup ID

Manual Plugin Installation – Download the Plugin from here, and install it in your Jenkins environment.

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

Screen Shot 2016-06-05 at 4.54.33 PM

Once you’ve set the Spotinst Token, scroll down near the bottom to the “Cloud” section. Click on the "Add a new cloud" button, and select the "Spotinst" option. If you are familiar with our Jenkins integration you will notice that there are now more fields that you can choose from. For more information on each field hover over the information button on the right side of each field. Specify your "Elastigroup ID" and "Idle minutes before termination".

We highly recommend configuring your Elastigroup for vCPU weighting to ensure the most efficient use of your resources

When creating your Elastigroup select “vCPU” as the unit as you can see below. This can be found on the “Strategy & Capacity” page of your Elastigroup configuration.

vCPU weight

 

 

That’s all, from now on – The Jenkins Master will automatically launch new instances through the Spotinst API, and will terminate them 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!