Build and Deploy a Maven Project

    At first, the Jenkins Master creates a Pod to run the pipeline. Kubernetes creates the Pod as the agent of Jenkins Master, and the Pod will be destroyed after the pipeline finished. The main process includes cloning code, building and pushing an image, and deploying the workload.

    Execute the following command in the Maven builder container to get version information.

    Maven cache

    The Jenkins Agent mounts the directories by Docker Volume on the node. The pipeline can cache some special directories such as /root/.m2, which are used for Maven building and the default cache directory for Maven tools in KubeSphere DevOps, so that dependency packages are downloaded and cached on the node.

    Global Maven settings in the Jenkins Agent

    The default file path of Maven settings is maven and the configuration file path is . Execute the following command to get the content of Maven settings.

    The Pod labeled maven uses the docker-in-docker network to run the pipeline. Namely, /var/run/docker.sock in the node is mounted to the Maven container.

    Prepare for the Maven project

    Create credentials

    For details, refer to the Credential Management.

    In this example, all workloads are deployed in . You must create the project kubesphere-sample-dev in advance.

    view-namespace

    Create a pipeline for the Maven project

    1. Go to Pipelines of your DevOps project and click Create. For more information, see Create a Pipeline - using Graphical Editing Panel.

    2. Go to the detail page of the pipeline and click Edit Jenkinsfile.

    3. Copy and paste the following content into the pop-up window. You must replace the value of DOCKERHUB_NAMESPACE with yours. When you finish, save it.

    4. Save the Jenkinsfile and you can see stages and steps are automatically created on graphical editing panels.

    Run and test

    1. Click Run and type to run the pipeline.

      run-maven-pipeline

    2. You can see the following figure when the pipeline finished.

    3. In the project of kubesphere-sample-dev, there are new workloads created.

      view-result-maven-workload