I have several projects running in Java 1.8 and Jenkins groovy script + Ansible acting as a pipleine to do deploys. Some of the projects are now migrated to Java 11 (OpenJDK). How do I configure Jenkins to build these projects in migrated to Java 11?
In Jenkins 2.x, under Jenkins | Manage Jenkins | Global Tool Configuration,
you should find a section "JDK Installations".
Configure multiple your jdk there. I'd not recommend "Install automatically" for Oracle JDK given their licensing changes since April 2019.

This question describes handling multiple jdk in a pipeline.
Corresponding the names in the image example the tools values would be:
tools {
jdk 'jdk1.8'
jdk 'jdk1.6'
}
For maven,
Use a maven toolchain / profiles to be able to dynamically choose which to use: https://maven.apache.org/guides/mini/guide-using-toolchains.html
https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html
ps: for freestyle jobs, the choice in in the General tab:

Note: if only one JDK is available, the option is hidden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With