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 user needs to be invited into the DevOps project with the role of . For more information, see Create Workspaces, Projects, Users 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 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
- 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-maven-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 kubesphere-sample-dev
. 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 to create a pipeline named . For more information, see Create a Pipeline - using Graphical Editing Panel.
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.You can see stages and steps are automatically created on graphical editing panels.
Run and test
Click Run, enter
v1
for TAG_NAME in the displayed dialog box, and then click OK to run the pipeline.When the pipeline runs successfully, you can go to the Run Records tab to view its details.