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 Pod labeled 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 kubesphere-sample-dev. You must create the project kubesphere-sample-dev in advance.

    Create a pipeline for the Maven project

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

    2. Copy and paste the following content into the displayed dialog box. You must replace the value of DOCKERHUB_NAMESPACE with yours. When you finish editing, click OK to save the Jenkinsfile.

    3. You can see stages and steps are automatically created on graphical editing panels.

    Run and test

    1. Click Run, enter v1 for TAG_NAME in the displayed dialog box, and then click OK to run the pipeline.

    2. When the pipeline runs successfully, you can go to the Run Records tab to view its details.