Build and Deploy a Maven Project
- You need to enable the KubeSphere DevOps System.
- You need to have a account.
- You need to create a workspace, a DevOps project, and a user account, and this account needs to be invited into the DevOps project with the role of . For more information, see Create Workspaces, Projects, Accounts and Roles.
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
- Ensure you build the Maven project successfully on the development device.
- Add the YAML file to the project repository to deploy the workload. For more information, refer to https://github.com/kubesphere/devops-java-sample/tree/master/deploy/dev-ol. If there are different environments, you need to prepare multiple deployment files.
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.
Create a pipeline for the Maven project
Go to Pipelines of your DevOps project and click Create. For more information, see Create a Pipeline - using Graphical Editing Panel.
Go to the detail page of the pipeline and click Edit Jenkinsfile.
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.Save the Jenkinsfile and you can see stages and steps are automatically created on graphical editing panels.
Run and test
Click Run and type to run the pipeline.
You can see the following figure when the pipeline finished.
In the project of
kubesphere-sample-dev
, there are new workloads created.