Merge "Parameterize the JDK distribution"
diff --git a/jjb/cord-onos-app-publishing.yaml b/jjb/cord-onos-app-publishing.yaml
index e566ef6..4ba0f40 100644
--- a/jjb/cord-onos-app-publishing.yaml
+++ b/jjb/cord-onos-app-publishing.yaml
@@ -28,6 +28,11 @@
          default: 'teo@opennetworking.org, saurav.das@opennetworking.org'
          description: ''
 
+      - string:
+         name: jdkDistro
+         default: '{jdk-distribution}'
+         description: 'Distribution of the JDK to use with update-java-alternatives'
+
     node: 'ubuntu16.04-basebuild-1c-2g'
     project-type: pipeline
     concurrent: true
diff --git a/jjb/defaults.yaml b/jjb/defaults.yaml
index a87efc1..fbba5b5 100644
--- a/jjb/defaults.yaml
+++ b/jjb/defaults.yaml
@@ -174,3 +174,7 @@
     # Currently used with: github-release
     artifact-glob: ''
 
+    # JDK distribution to use
+    # Give the version of the JDK to use when building
+    # Parameter is used with `update-java-alternatives --set <jdk-distribution>`
+    jdk-distribution: 'java-11-amazon-corretto'
diff --git a/jjb/maven.yaml b/jjb/maven.yaml
index 522c107..3fe240f 100644
--- a/jjb/maven.yaml
+++ b/jjb/maven.yaml
@@ -22,6 +22,11 @@
          default: 'refs/heads/master'
          description: 'Use default when using "Build Now"'
 
+      - string:
+         name: jdkDistro
+         default: '{jdk-distribution}'
+         description: 'Distribution of the JDK to use with update-java-alternatives'
+
     triggers:
       - cord-infra-gerrit-trigger-patchset:
           gerrit-server-name: '{gerrit-server-name}'
@@ -53,6 +58,15 @@
       - inject:
           properties-content: |
             _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true
+
+      - shell: |
+          #!/usr/bin/env bash
+          set -eu -o pipefail
+          echo "Setting JDK Distro to: $jdkDistro"
+          sudo update-java-alternatives -set "$jdkDistro"
+          echo "Java Version:"
+          java -version
+
       - maven-target:
           pom: pom.xml
           goals: 'clean install'
@@ -78,6 +92,11 @@
          default: 'refs/heads/master'
          description: 'Use default when using "Build Now"'
 
+      - string:
+         name: jdkDistro
+         default: '{jdk-distribution}'
+         description: 'Distribution of the JDK to use with update-java-alternatives'
+
     triggers:
       - cord-infra-gerrit-trigger-merge:
           gerrit-server-name: '{gerrit-server-name}'
@@ -104,6 +123,15 @@
       - inject:
           properties-content: |
             _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true
+
+      - shell: |
+          #!/usr/bin/env bash
+          set -eu -o pipefail
+          echo "Setting JDK Distro to: $jdkDistro"
+          sudo update-java-alternatives -set "$jdkDistro"
+          echo "Java Version:"
+          java -version
+
       - maven-target:
           pom: pom.xml
           settings: onoscord-apps
@@ -117,6 +145,12 @@
       <!-- Managed by Jenkins Job Builder -->
       Created by {id} job-template from ci-management/jjb/maven.yaml
 
+    parameters:
+      - string:
+         name: jdkDistro
+         default: '{jdk-distribution}'
+         description: 'Distribution of the JDK to use with update-java-alternatives'
+
     triggers:
       - cord-infra-gerrit-trigger-patchset:
           gerrit-server-name: '{gerrit-server-name}'
@@ -158,6 +192,15 @@
       - inject:
           properties-content: |
             _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true
+
+      - shell: |
+          #!/usr/bin/env bash
+          set -eu -o pipefail
+          echo "Setting JDK Distro to: $jdkDistro"
+          sudo update-java-alternatives -set "$jdkDistro"
+          echo "Java Version:"
+          java -version
+
       - maven-target:
           pom: pom.xml
           goals: 'test'
diff --git a/jjb/onos-app-release.yaml b/jjb/onos-app-release.yaml
index 5790821..0d780d8 100644
--- a/jjb/onos-app-release.yaml
+++ b/jjb/onos-app-release.yaml
@@ -49,6 +49,11 @@
          default: 'master'
          description: 'Name of the branch to release on.'
 
+      - string:
+         name: jdkDistro
+         default: '{jdk-distribution}'
+         description: 'Distribution of the JDK to use with update-java-alternatives'
+
     node: 'ubuntu16.04-basebuild-1c-2g'
     project-type: pipeline
     concurrent: true