Skip to content

Instantly share code, notes, and snippets.

@mkutz
Created November 12, 2018 15:48
Show Gist options
  • Save mkutz/046038d07859b7d408accd162ab93b2d to your computer and use it in GitHub Desktop.
Save mkutz/046038d07859b7d408accd162ab93b2d to your computer and use it in GitHub Desktop.
Configure JDK installations in Jenkins using a post-initialization script (https://wiki.jenkins.io/display/JENKINS/Post-initialization+script)
import hudson.model.JDK
/*
* Configure the locations of multiple JDKs
* Note that this won't install anything, it just makes Jenkins aware of JDK installations
*/
Jenkins.instance.getDescriptor(JDK).setInstallations(
new JDK("11", "/usr/lib/jvm/java-11-openjdk-amd64/"),
new JDK("8", "/usr/lib/jvm/java-8-openjdk-amd64/")
)
pipeline {
agent any
tools {
jdk "11"
}
stages {
stage("Use maven") {
steps {
sh "java -version"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment