Skip to content

java ci

devonfw-core edited this page Jan 27, 2022 · 10 revisions

Java CI

The Java server-side of My Thai Star is an devon4j-based application. As long as Maven and a Java 8 are going to be needed, the Pipeline should have those tools available as well.

Pipeline

This Pipeline is called MyThaiStar_SERVER_BUILD, and it is located exactly in the same PL instance’s folder than MyThaiStar_FRONTEND_BUILD. Let’s see how the Pipeline’s flow behaves.

java pipeline flow

Check those Pipeline stages with more detail:

  1. Declarative: Checkout SCM

    Gets the code from https://github.com/devonfw/my-thai-star . This step is not defined directly in our pipeline, but as it is loaded from the repository this step should always be done at the beginning.

  2. Declarative: Tool Install

    The My Thai Star application works with JDK11. In this step, if JDK11 is not installed, we install it and then put the JDK folder into PATH.

    tools {
      jdk 'OpenJDK11'
    }
  3. Loading Custom Tools

    In this step we load the tools that can not be loaded in the previous step. As My Thai Star is delivered as docker container, in this step we load docker as custom tool.

    tool dockerTool
  4. Install dependencies

    This step will download all project dependencies.

    mvn clean install -Dmaven.test.skip=true
  5. Unit Tests

    This step will execute the project unit test with maven.

    mvn clean test
  6. Dependency Checker

    Execute the OWASP Dependency Checker in order to validate the project dependencies. It will generate a report that can be used in SonarQube

    dependencyCheck additionalArguments: '--project "MTSJ" --scan java/mtsj --format XML', odcInstallation: 'dependency-check'
    dependencyCheckPublisher pattern: ''
  7. SonarQube analysis

    The code is evaluated using the integrated PL instance’s SonarQube. Also, it will wait for the quality gate status. If the status is failing, the pipeline execution will be stopped.

    withSonarQubeEnv(sonarEnv) {
        sh "mvn sonar:sonar"
    }
    
    def qg = waitForQualityGate()
    if (qg.status != 'OK') {
        error "Pipeline aborted due to quality gate failure: ${qg.status}"
    }
  8. Deliver application into Nexus

    Store all artifacts into nexus.

    mvn deploy -Dmaven.test.skip=true
  9. Create the Docker image

    Create the docker image and then publish the image into a docker registry.

Adjustments

Pipeline Environment

In order to easily reuse the pipeline in other java projects, all variables have been defined in the block environment. All variables have the default values that Production Line uses, so if you’re going to work in production line you won’t have to change anything. Example:

environment {
    // Directory with java project
    javaDir = 'java/mtsj'

    // SonarQube
    // Name of the SonarQube environment
    sonarEnv = "SonarQube"

    // Nexus 3
    // Maven global settings configuration ID
    `globalSettingsId = 'MavenSettings'`
    // Maven tool id
    `mavenInstallation = 'Maven3'`

    // Docker
    dockerRegistryCredentials = 'nexus-api'
    dockerRegistryProtocol = 'https://\'
    dockerTool = 'docker-global
}

Description

  • java Dir: Relative route to java application. In My Thai Star this is the java/mtsj folder. The actual directory (.) is also allowed.

    java directory
  • sonar Env: Name of the SonarQube environment. SonarQube is the default value for PL.

  • global Settings Id: The id of the global settings file. MavenSettings is the default value for PL.

    nexus3 global config
  • maven Installation: The name of the maven tool. Maven3 is the default value for PL.

    maven tool

Distribution management

The only extra thing that needs to be added to the Java server-side is some information that determines where the artifact of the project is going to be stored in Nexus. This is going to be a section in the main pom.xml file called <distributionManagement>. This section will point to the PL instance’s Nexus. Let’s have a look at it. It’s already configured with the PL default values.

<distributionManagement>
    <repository>
      <id>pl-nexus</id>
      <name>PL Releases</name>
      <url>http://nexus3-core:8081/nexus/content/repositories/maven-releases/</url>
    </repository>
    <snapshotRepository>
      <id>pl-nexus</id>
      <name>PL Snapshots</name>
      <url>http://nexus3-core:8081/nexus3/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>
Clone this wiki locally