At a minimum, the init script needs to install a Java runtime.

Custom prepared images are recommended if the initialization script is taking more than 20 minutes to execute.

Below are examples of initialization scripts:

  1. Ubuntu

    # Install Java
    sudo apt-get -y update
    sudo apt-get install -y openjdk-7-jdk
    # Install Git
    sudo apt-get install -y git

  2. Windows w/JNLP

    For Windows agents with JNLP launch, this script is a powershell script. You can use this sample.

    Arguments automatically passed to this script are:

    • First argument - Jenkins server URL
    • Second argument - VMName
    • Third argument - JNLP secret, required if the server has security enabled.

    You need to install Java, download the slave jar file from: '[server url]jnlpJars/slave.jar'.

    # Download and Install Java
    $source = "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-windows-x64.exe"
    $destination = "C:\jdk-8u131-windows-x64.exe"
    $client = new-object System.Net.WebClient
    $cookie = "oraclelicense=accept-securebackup-cookie"
    $client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
    $client.downloadFile($source, $destination)
    $proc = Start-Process -FilePath $destination -ArgumentList "/s"m -Wait -PassThru
    $proc.WaitForExit()
    [System.Environment]::SetEnvironmentVariable("JAVA_HOME", "c:\Program Files\Java\jdk1.8.0_131", "Machine")
    [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";c:\Program Files\Java\jdk1.8.0_131\bin", "Machine")

    The server url should already have a trailing slash. Then execute the following to connect:

    java.exe -jar [slave jar location] [-secret [client secret if required]] [server url]computer/[vm name]/slave-agent.jnlp