Skip to content

Create a Pipeline

This section will provide a step-by-step guide to create a pipeline through editing, building, and deploying, enabling you to quickly set up a pipeline.

Prerequisites

  • You need to create a workspace and a user. This user should join the workspace and be assigned the Workspace Editor role. Refer to Creating Workspace and Users.
  • Create two credentials that can access the container registry and the cluster, named: registry and kubeconfig respectively. For more information on creating credentials, refer to Credential Management.
  • Prepare a GitHub repository and a DockerHub repository.

Create credentials

  1. Create two credentials on the Credentials page:

    • docker-credential: Username and password for accessing the container registry.
    • demo-dev-kubeconfig: To access the Kubernetes cluster using this kubeconfig.
  2. After creation, you can see the credential information on the credential list page.

Create a custom pipeline

  1. Click Create Pipeline on the pipeline list page.

    Create Pipeline

  2. In the pop-up dialog box, select Create a custom pipeline , then click OK .

    Custom Pipeline

  3. Enter test-demo as the pipeline name on the Create a custom pipeline page.

    Basic Info

  4. Add three string parameters in Build Parameters , these parameters will be used in the image build command.

    • registry: Container Registry address. Example value: release.daocloud.io .
    • project: The project name in the container registry. Example value: demo .
    • name: The name of the image. Example value: http-hello .

    Build Parameters

  5. After adding, click OK .

Edit pipeline

  1. Click a pipeline's name on the pipeline list page.

    Pipeline List

  2. Click Edit Pipeline in the upper right corner.

    pipelisetting

  3. Click Global Settings in the upper right corner.

    pipelisetting

  4. Set the type to node , and label to go , then click OK .

    pipelisetting

  5. Add stage -> Pull Source Code.

    • Click Add Stage on the canvas. Set the name in the stage settings on the right to: git clone.
    • Click Add Step , select git clone under step type in the pop-up dialog box, and configure the relevant parameters:
      • Repo URL: Enter the GitLab repository address.
      • Branch: If not filled in, the default is the master branch.
      • Credential: If it is a private repository, you need to provide a credential.

    Add Stage

  6. Add stage -> Build and Push Image.

    • Click Add Stage on the canvas. Set the name in the stage settings on the right to: build & push.

    • In the step module, select to enable Specify Container , fill in the container name go in the pop-up dialog box, then click OK .

      Specify Container01

    • In the step module, select to enable Use Credential, fill in the relevant parameters in the pop-up dialog box, then click OK .

      • Credentials: Select the Docker hub credentials you created for accessing the container registry.
      • Password Variable: PASS
      • Username Variable: USER

      Use Credential01

    • Click Add Step to build the code, select shell under step type in the pop-up dialog box, and enter the following command in the command line, then click OK .

      go build -o simple-http-server main.go
      
    • Click Add Step to build a Docker image according to the Dockerfile in the source code, select shell under step type in the pop-up dialog box, and enter the following command in the command line, then click OK .

      docker build -f Dockerfile . -t $registry/$project/$name:latest
      
    • Click Add Step to log in to the container registry, select shell under step type in the pop-up dialog box, and enter the following command in the command line, then click OK .

      docker login $registry -u $USER -p $PASS
      
    • Click Add Step to push the image to the container registry, select shell under step type in the pop-up dialog box, and enter the following command in the command line, then click OK .

      docker push $registry/$project/$name:latest
      
  7. Add stage -> Deploy to Cluster.

    • Click Add Stage on the canvas. Set the name in the stage settings on the right to: deploy.

    • In the step module, select to enable Specify Container , fill in the container name go in the pop-up dialog box, then click OK .

      Specify Container02

    • In the step module, select to enable Use Credential , fill in the relevant parameters in the pop-up dialog box, then click OK .

      • Credentials: Choose the kubeconfig type credential.
      • kubeconfig Variable: If you are using the kubectl apply deployment method, the variable value must be KUBECONFIG.

      Use Credential02

    • Click Add Step to deploy to the cluster, select shell under step type in the pop-up dialog box, and enter the following command in the command line, then click OK.

      kubectl apply -f deploy.yaml
      

Save and run pipeline

  1. After completing the previous step, click Save and Run .

    Save and Run

  2. In the pop-up dialog box, input the example parameters from step two. Click OK to successfully run the pipeline.

    Run Successfully

Comments