7. Setting up Jenkins to use Java and Maven

Adarsh BhaskarAdarsh Bhaskar
2 min read

Jenkins Global Tool Configuration

This guide specifically applies to Jenkins services deployed in Microk8s via Helm chart. The configuration described here enables Jenkins to build and test Java applications as part of a CI/CD pipeline. It's important to understand that this method configures the tools at the Jenkins level rather than within individual pods or containers.

This method is most effective when Jenkins agents are traditional virtual machines or physical servers, not ephemeral Kubernetes pods. In a Kubernetes environment, using pre-baked Docker images is generally preferred.

Steps:

  1. Access Jenkins:

    • Open your web browser and navigate to your Jenkins URL.

    • Log in with your administrator credentials.

  2. Navigate to Global Tool Configuration:

    • Click on "Manage Jenkins" in the left-hand menu.

    • Select "Global Tool Configuration."

  3. Configure JDK (Java Development Kit):

    • Find the "JDK installations..." section.

    • Click "Add JDK."

    • Name: Give your JDK installation a descriptive name (e.g., "OpenJDK 11").

    • Install automatically: Check this box if you want Jenkins to download and install the JDK.

      • Installer: Select the appropriate JDK installer (e.g., "Install from Oracle" or "Install from AdoptOpenJDK"). You'll likely need to agree to license terms.

      • Version: Choose the desired JDK version.

    • Or, provide JDK manually: If you've already installed the JDK on your agent machines, you can provide the JAVA_HOME path.

    • Click "Save."

  4. Configure Maven:

    • Find the "Maven installations..." section.

    • Click "Add Maven."

    • Name: Give your Maven installation a descriptive name (e.g., "Maven 3.8").

    • Install automatically: Check this box to let Jenkins download and install Maven.

      • Version: Select the desired Maven version.

      • Install from Apache: select this.

    • Or, provide Maven manually: If you've already installed Maven on your agent machines, provide the MAVEN_HOME path.

    • Click "Save."

Important Considerations:

  • Agent Connectivity: Jenkins agents must have internet access to download the tools.

  • Permissions: The Jenkins user on the agent machines must have the necessary permissions to install software.

  • Agent Configuration: For this to work, the agents must be configured to use the "Tool Locations" defined in Jenkins. If you are using traditional agents, and you are launching them via ssh, they will use these settings.

  • Kubernetes: As mentioned, this method is less suitable for Kubernetes. Use pre-baked images instead.

  • Plugins: Ensure you have installed “maven-integration” plugin for jenkins in “Available plugins”.

0
Subscribe to my newsletter

Read articles from Adarsh Bhaskar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Adarsh Bhaskar
Adarsh Bhaskar

Hi there! I’m Adarsh, a passionate information science student with hands-on experience in machine learning, software development, and data analysis. I thrive on solving complex problems and enjoy collaborating with teams to bring innovative solutions to life. Whether it’s developing a recommendation engine or streamlining workflows with automation, I love diving into new technologies. I’m always eager to learn and explore fresh ideas, especially in the world of Flutter app development!