May 17, 2018

Jenkins, Groovy init scripts and custom Tools

Filed under: General Information,ResearchAndDevelopment — Ryan Wilcox @ 10:56 pm

I’ve been working with Jenkins quite a bit lately.

When I set up a system I want it to be as reproducable as possible: you can never trust hardware, especially when it’s virtual.

I found Accenture’s Jenkins Docker configuration . It’s super good, especially as a basis of sample code. Based on this code I was able to install and configure plugins (ie I set up a Node.js Jenkins tool, etc etc).

My Jenkins installation also uses the CustomTool Plugin extensively, to provide CLI tools to my Jenkins pipelines. So I wanted to add my custom tool configuration to my Jenkins init scripts.

There’s plenty of documentation on installing tools based on plugins (even a section of my learning notes!) but the custom tools plugin seems to be left out of this flurry of documentation. No longer!

Installing custom tools is a bit different from installing tools that come explicitly as part of a plugin, and here is some code that worked for me:

import jenkins.model.*
import com.cloudbees.jenkins.plugins.customtools.CustomTool;
import com.synopsys.arc.jenkinsci.plugins.customtools.versions.ToolVersionConfig;


def installs = a.getInstallations()
def found = installs.find { == "gcc"

if ( found ) {
println "gcc is already installed"
} else {
println "installing gcc tool"

def newI = new CustomTool("gcc", "/usr/local/gcc/", null, "bin", null, ToolVersionConfig.DEFAULT, null)
installs += newI
a.setInstallations( (com.cloudbees.jenkins.plugins.customtools.CustomTool[])installs );



  1. Hi,

    nice codesnippet Ryan, thanks! Have you tried adding a download URL and zip extraction?
    No success for me :(


    Comment by Tim — September 25, 2018 @ 5:48 am

  2. Hi Tom,

    I managed to create a CustomTool that uses a Batch Command installer to install kubectl.
    Here is the code:

    import jenkins.model.*
    import com.cloudbees.jenkins.plugins.customtools.*
    import com.synopsys.arc.jenkinsci.plugins.customtools.versions.ToolVersionConfig

    def KUBECTL_VERSION = “1.12.2”

    def inst = Jenkins.getInstance()
    def desc = inst.getExtensionList(com.cloudbees.jenkins.plugins.customtools.CustomTool.DescriptorImpl.class)[0]
    def customTools = []

    List installers = new ArrayList();
    installers.add(new BatchCommandInstaller(null,
    “curl –silent“+KUBECTL_VERSION+”/bin/linux/amd64/kubectl > /dev/null\n” +
    “chmod +x ./kubectl”,

    List<ToolProperty> properties = new ArrayList<ToolProperty>()
    properties.add(new InstallSourceProperty(installers))

    def installation = new CustomTool(


    desc.setInstallations((com.cloudbees.jenkins.plugins.customtools.CustomTool[]) customTools)

    In order to use the zip extraction you will need to replace the BatchCommandInstaller with a ZipExtractionInstaller with the necessary setup.

    Comment by Darius — December 5, 2018 @ 9:32 am

RSS feed for comments on this post. TrackBack URI

Leave a comment