Skip to content

Instantly share code, notes, and snippets.

@mkutz
Last active November 13, 2018 11:22
Show Gist options
  • Save mkutz/97b7b3dda945dfba27e495d6349b9fec to your computer and use it in GitHub Desktop.
Save mkutz/97b7b3dda945dfba27e495d6349b9fec 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 java") {
steps {
echo env.JAVA_HOME
sh "java -version"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment