I want to use different JDK versions for different stages in Jenkins declarative pipeline. In the first stage I am using Java 8. In the second stage i am using Java 6. How to select multiple JDK version in declarative pipeline in Jenkins?
pipeline {
agent any
tools {
jdk 'jdk_1.8.0_151'
jdk 'jdk_1.6.0_45'
}
stages {
stage('java 8') {
steps {
sh 'java -version'
sh 'javac -version'
}
}
stage('java 6') {
steps {
sh 'java -version'
sh 'javac -version'
}
}
}
}
you can add a tools section for each stage.
From the Pipeline tools directive:
From the pipeline-examples and cloudbess example:
I would recommend you to use different docker images for each stage if you want to have different JDK versions. You can achieve using the docker hub openjdk images with the correct tag. https://hub.docker.com/r/library/openjdk/
https://hub.docker.com/r/library/openjdk/tags/ Something like that:
}