Deploying A Spring Boot Application to Openshift, with Java 11 S2I and Jenkins Pipeline
Openshift provide a base Java s2i image where we can use as a base image to run our java applicaiton. But too bad, the default Java base image is still using java 8. On this example, im trying to do a simple deployment to Openshift but using Java 11 as its base image, instead of Java 8.
First we need to import a Java 11 s2i image from Red Hat Registry, it will become our base image to run our executable java app.
oc import-image my-project/openjdk-11-rhel7 --from=registry.redhat.io/openjdk/openjdk-11-rhel7 --confirm
Next is creating a very simple pipeline script to build, and deploy our app using Jenkins Pipeline.
node('maven') { stage('Clone') { sh "git config --global http.sslVerify false" sh "git clone https://github.com/edwin/hello-world.git" } stage('Build') { sh "mvn -v" sh "mvn clean package -f hello-world/pom.xml" def jarFile = sh(returnStdout: true, script: 'find hello-world/target -maxdepth 1 -regextype posix-extended -regex ".+\\.(jar|war)\$" | head -n 1').trim() sh "cp ${jarFile} app.jar" } stage('Deploy') { sh "oc new-build --name hello-world --binary -n my-project --image-stream=my-project/openjdk-11-rhel7 || true" sh "oc start-build hello-world --from-file=app.jar -n my-project --follow --wait" sh "oc new-app hello-world || true" sh "oc expose svc/hello-world || true" } }