This document demonstrates how to create a pipeline using a pipeline template on KubeSphere.

DevOps provides a graphical editing panel that supports defining Jenkins pipeline stages and steps through interactive operations. It includes several built-in pipeline templates, such as Node.js, Maven, and Golang, allowing users to quickly create pipelines based on these templates. DevOps also provides CI and CI & CD pipeline templates. However, these two templates may not meet customization needs. It is recommended to use other built-in templates or create a custom pipeline directly.

  • CI Pipeline Template

    The CI pipeline template contains two stages. The clone code stage is used to check out the code, and the build & push stage is used to build the image and push it to Docker Hub. First, create credentials for the code repository and the Docker Hub repository. Then, set the repository URLs and credentials in the corresponding steps. After editing is complete, the pipeline can start running.

  • CI & CD Pipeline Template

    The CI & CD pipeline template contains six stages. For more information about each stage, please refer to Create a Pipeline Using a Jenkinsfile. First, create credentials for the code repository, Docker Hub repository, and the cluster’s kubeconfig. Then, set the repository URLs and credentials in the corresponding steps. After editing is complete, the pipeline can start running.

Prerequisites

  • The DevOps extension must be installed and enabled on the KubeSphere platform.

  • A workspace, a DevOps project, and a user (e.g., project-regular) have been created. The user has been invited to the DevOps project and granted the operator role. Please refer to Invite a User to a DevOps Project.

Steps

The following uses Node.js as an example to demonstrate how to use a built-in pipeline template. The operations for using the Maven and Golang pipeline templates are basically the same.

  1. Log in to the KubeSphere console as the project-regular user and enter your workspace.

  2. Click  DevOps > Pipelines in the left navigation pane.

  3. Select a DevOps project from the drop-down list in the upper left corner of the page.

  4. Click Create on the page.

  5. In the dialog box that appears, enter a pipeline name, click Next, and then click Create.

  6. Click the created pipeline. On the Pipeline Configuration tab, click Edit Pipeline.

  7. In the Create Pipeline dialog box, click Node.js, and then click Next.

  8. On the Parameter Settings tab, set the following parameters according to the actual situation, and then click Create.

    Parameter Description

    GitURL

    The address of the project repository to be cloned.

    GitRevision

    The branch to be checked out.

    NodeDockerImage

    The Docker image version for Node.js.

    InstallScript

    The Shell script for installing dependencies.

    TestScript

    The Shell script for project testing.

    BuildScript

    The Shell script for building the project.

    ArtifactsPath

    The path where the artifact files are located.

  9. On the left-side visual editing page, a series of steps are added by default. Click Add Step or Add Parallel Stage to make modifications.

  10. Click a step. On the right side of the page, you can perform the following operations. After editing, click OK.

    • Modify the stage name.

    • Delete the stage.

    • Set the agent type.

    • Add conditions.

    • Edit or delete a task.

    • Add steps or nested steps.

    Note

    Please refer to Create a Pipeline Using the Graphical Editing Panel to learn how to customize steps and stages in a pipeline template.

  11. In the Agent area on the right, select the agent type. The default value is kubernetes. Click OK.

    Agent Type Description

    any

    Invokes the default base pod template to create a Jenkins agent to run the pipeline.

    node

    Invokes a specified type of pod template to create a Jenkins agent to run the pipeline. Configurable label tags include base, java, nodejs, maven, go, etc.

    kubernetes

    Uses a standard Kubernetes pod template defined by a YAML file to run the agent and execute pipeline tasks.

  12. Review the details of the created pipeline template, and click Run to execute the pipeline.