Child pages
  • DigitalOcean Plugin
Skip to end of metadata
Go to start of metadata

Plugin Information

View DigitalOcean on the plugin site for more information.

Allow Jenkins to start slaves on DigitalOcean droplets on demand and destroy them as they get unused.

Configure plugin via Groovy script

Either automatically upon Jenkins post-initialization or through Jenkins script console, example:

import com.dubture.jenkins.digitalocean.DigitalOceanCloud
import com.dubture.jenkins.digitalocean.SlaveTemplate
import jenkins.model.Jenkins

// parameters
def slaveTemplateParameters = [
  idleTerminationInMinutes: '10',
  imageId:                  'ubuntu-17-10-x64',
  initScript:               '',
  installMonitoring:        false,
  instanceCap:              '2',
  labellessJobsAllowed:     false,
  labelString:              'digitalocean.toronto.ubuntu.17.10',
  name:                     'digitalocean.toronto.ubuntu.17.10',
  numExecutors:             '1',
  regionId:                 'tor1',
  sizeId:                   '512mb',
  sshPort:                  22,
  tags:                     '',
  userData:                 '',
  username:                 'root',
  workspacePath:            '/home/jenkins'
]

def cloudParameters = [
  authToken:            '01234567890123456789012345678901234567890123456789',
  connectionRetryWait:  '30',
  instanceCap:          '2',
  name:                 'mycompany',
  sshKeyId:             '01234567',
  timeoutMinutes:       '10',
  usePrivateNetworking: false,
  privateKey:     '''-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgGuoiHtwl8T2cKfclsWLOcv8S6p74iOAQX1kwCLvLy7ioDFlNzsI
U235N1StnZYZIwGla+3Uo3jMSUuWkMH85+d3KoRFPS+6RJCiAvMI0hr8FByes22v
DAVDnhkZ2SFOeh1SPxWDygPo2fW5sgqL2eYLO1CplDdqYhHLAL1FDV5tAgMBAAEC
gYBWRZoJgXK9zdb9TZIs/6LzSlzAY8IWPOM+PwyRcibXZZiFvNyDm+pviHTEkNRl
wgMBgLR6xBmz5dEel6utKKQVEPtD1m6N+z6hwUw+Nis35DCvmBX+hQSK+atGgjYH
ZKz0oqWUSuzHG+CxxcrePDTYJ4fdSyLPsQqaWoCZseDDwQJBANLey9r+juBEQe2N
MJoZTU1q/AoS5kY7OWQ1aF495I9fz87u9vx8BJh8djvmABwidUWREnd4vwwEIS3M
JtFGn+kCQQCCsvBvOXgVAlcR54/6ro6R42/0F3bZw0ZFVXvgRRjCZW6m4FyHq4AL
+gfAV0HERkMdlO1zBpBwkSURekDc9NvlAkAA3zj6k9jlZoLbR50u1fHy4wFdzUw0
eCQ5nNrsoNbkHOJQGb7dtmmSc9lNUBsqAp53hi0MX2xy0UWN2e1DKkaZAkBi9stH
7OQYRGVZkVVcI8Cghu7GjN3ZlhsndMsPzkIpMFTQ1yI5OIsEhpZH9co+rFU1mQcT
Ce1kzwKacU+b/2xhAkEAovqzUMFB9YEbc8C9AzTej5F2ttyuKBDJJ+kvQeJP+PnW
4ovFI4Ee5UmTWI6k/Md9BM+MvEMWs3nPoF4MULHqNg==
-----END RSA PRIVATE KEY-----'''
]

// https://github.com/jenkinsci/digitalocean-plugin/blob/digitalocean-plugin-0.17/src/main/java/com/dubture/jenkins/digitalocean/SlaveTemplate.java
SlaveTemplate slaveTemplate = new SlaveTemplate(
  slaveTemplateParameters.name,
  slaveTemplateParameters.imageId,
  slaveTemplateParameters.sizeId,
  slaveTemplateParameters.regionId,
  slaveTemplateParameters.username,
  slaveTemplateParameters.workspacePath,
  slaveTemplateParameters.sshPort,
  slaveTemplateParameters.idleTerminationInMinutes,
  slaveTemplateParameters.numExecutors,
  slaveTemplateParameters.labelString,
  slaveTemplateParameters.labellessJobsAllowed,
  slaveTemplateParameters.instanceCap,
  slaveTemplateParameters.installMonitoring,
  slaveTemplateParameters.tags,
  slaveTemplateParameters.userData,
  slaveTemplateParameters.initScript
)

// https://github.com/jenkinsci/digitalocean-plugin/blob/digitalocean-plugin-0.17/src/main/java/com/dubture/jenkins/digitalocean/DigitalOceanCloud.java
DigitalOceanCloud digitalOceanCloud = new DigitalOceanCloud(
  cloudParameters.name,
  cloudParameters.authToken,
  cloudParameters.privateKey,
  cloudParameters.sshKeyId,
  cloudParameters.instanceCap,
  cloudParameters.usePrivateNetworking,
  cloudParameters.timeoutMinutes,
  cloudParameters.connectionRetryWait,
  [slaveTemplate]
)

// get Jenkins instance
Jenkins jenkins = Jenkins.getInstance()

// add cloud configuration to Jenkins
jenkins.clouds.add(digitalOceanCloud)

// save current Jenkins state to disk
jenkins.save()

4 Comments

  1. Thank you for putting this plugin together. It appears to be working good so far.  However, I have a few questions:

    • Are there any plans to upgrade this plugin to use DigitalOcean's API v2? API v1 is deprecated and scheduled to end in November 2015.
    • Is there a way to change the number of executors? From what I can tell, it looks like the plugin has this locked in at 1 executor per droplet. So if I have a 2 CPU image, I'd imagine being able to have at most 2 executors per droplet. Or is the workaround simply to just add more droplets on the Configure System page?
    • It appears that the "idle termination time" isn't being honored. For example, when I set this value to 5 minutes, the node remains active. I actually waited for about an hour before the node got deleted.
  2. Could you please provide the documentation how to use this plugin in Jenkins pipeline.

    • I am able to install this plugin in jenkins and able to configure the Digital Ocean as a cloud in jenkins, the test connection also succeed with the response "Digitalocean API request succeeded".
    • I also configure the droplet section but not able to make sure that the droplet is created. And I am not sure how to use this droplet in my Jenkins pipeline.
    • Please do provide the steps how to use this as a slave in jenkins pipeline. 

     

  3. It'd be nice if this plugin was resuscitated. I use it in production for some time, but I cannot set it up any longer on recent versions of Jenkins (sad) I'll post something on Twitter for Digital Ocean, or I might even try to fix it myself.

  4. I've just published a Groovy script to configure this plugin, it would be nice to include it in the docs to help people that are looking to automate their Jenkins configuration/deployment.

    https://gist.github.com/ivan-pinatti/7f7af9efe655d26a41f3292174adb2ea

Write a comment…