< img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=3131724&fmt=gif" />

Create a Pipeline Using Graphic Editing Panels

The graphic editing panel in DevOps includes all the necessary operations for Jenkins Stages and Steps. DevOps supports defining these stages and steps directly on the interactive panel without the need to create any Jenkinsfile.

This section demonstrates how to use the graphic editing panel to create pipelines in KubeSphere. Throughout the process, DevOps will automatically generate a Jenkinsfile based on the settings on the editing panel, eliminating the need to manually create a Jenkinsfile. Once the pipeline runs successfully, it will push the image to Docker Hub.

Prerequisites

Pipeline Overview

This example pipeline consists of the following stages:

Note
  • Stage 1: Checkout SCM: Fetch the source code from the GitHub repository.

  • Stage 2: Unit Test: It will not proceed with the next stage until the test is passed.

  • Stage 3: Code Analysis: Configure SonarQube for static code analysis.

  • Stage 4: Build and Push: Build the image, tag it as snapshot-$BUILD_NUMBER, and push it to Docker Hub, where $BUILD_NUMBER is the run ID of the record in the pipeline run records.

  • Stage 5: Artifacts: Generate an artifact (JAR package) and save it.

Step 1: Create Credentials

  1. Log in to the KubeSphere web console as the project-regular user.

  2. Click Workspace Management and navigate to your DevOps project. Under DevOps Project Settings, create the following credentials in the Credentials page. For more information on creating credentials, refer to Credential Management.

    Note

    If your account or password contains special characters such as @ and $, errors may occur during pipeline runs due to unrecognized characters. In such cases, encode your account or password on a third-party website (e.g., urlencoder) and then copy and paste the encoded result as your credential information.

    Credential ID Type Where to use

    dockerhub-id

    Username and Password

    Docker Hub

  3. Create another credential for SonarQube (sonar-token) for Stage 3 (Code Analysis). Choose the credential type Access Token and enter the SonarQube token in the Token field. Refer to Create a SonarQube Token for the New Project. Click OK to complete the process.

  4. Once created, you will see the credentials on the credentials page.

Step 2: Create a Pipeline

  1. Log in to the KubeSphere web console as the project-regular user.

  2. Click Workspace Management and navigate to your DevOps project. Click Pipelines and then click Create.

  3. In the pop-up dialog, name it graphical-pipeline and click Next.

  4. On the Advanced Settings page, click Add to add the following string parameters. These parameters will be used for Docker commands in the pipeline. Once added, click Create.

    Parameter Type Name Value Description

    String

    REGISTRY

    docker.io

    Image registry address. This example uses docker.io.

    String

    DOCKERHUB_NAMESPACE

    Your Docker ID

    Your Docker Hub account or organization name under the account.

    String

    APP_NAME

    devops-sample

    Application name. This example uses devops-sample.

    Note

    For other fields, use default values or refer to Pipeline Settings for custom configurations.

Step 3: Edit the Pipeline

  1. Click the pipeline name to enter its details page.

  2. To use the graphical editing panel, click Edit Pipeline under the Pipeline Configurations tab. In the pop-up dialog:

    • Click Custom Pipeline and follow the steps to configure each stage.

    • Alternatively, use the built-in pipeline templates provided by DevOps.

  3. Click Next and then click Create.

Note

The Sync Status on the pipeline details page shows the synchronization result between KubeSphere and Jenkins. You can also click Edit Jenkinsfile to manually create a Jenkinsfile for the pipeline.

Stage 1: Fetch Source Code (Checkout SCM)

The graphical editing panel consists of two areas: the canvas on the left and the content on the right. It automatically generates a Jenkinsfile based on your configurations for different stages and steps, providing a more user-friendly experience for developers.

Note

The pipeline includes Declarative Pipeline and Scripted Pipeline. Currently, creating Declarative Pipelines using this panel is supported. For more information on pipeline syntax, refer to the Jenkins Documentation.

  1. On the graphical editing panel, select node from the Type dropdown list and maven from the Label dropdown list.

    Note

    Agent is used to define the execution environment. The Agent directive specifies where and how Jenkins executes the pipeline. For more information, see Choose Jenkins Agent.

    graphical panel

  2. Click the plus icon on the left to add a stage. Click the text box above Add Step and set the name for the stage on the right in the Name field (e.g., Checkout SCM).

    edit panel

  3. Click Add Step. Select Git Clone from the list to fetch sample code from GitHub. Fill in the required fields in the pop-up dialog. Click OK to confirm the operation.

    • URL: Enter the GitHub repository https://github.com/kubesphere/devops-maven-sample.git. Note that this is a sample address; please use your own repository address.

    • Credential ID: No need to input a credential ID in this example.

    • Branch: Enter v4.1.0-sonarqube. Use the default v4.1.0 branch if the code analysis stage is not required.

    enter repo url

Stage 2: Unit Test

  1. Click the plus icon to the right of Stage 1 to add a new stage for running unit tests in a container. Name it Unit Test.

    unit test

  2. Click Add Step, select Specify Container from the list. Name it maven and click OK.

    container maven

  3. Click the maven container step and Add nesting steps. Select shell from the list and enter the following command. Click OK to save it.

    mvn clean test
    Note

    In the graphical editing panel, you can specify a series of steps to be executed within a given stage.

Stage 3: Code Analysis (Optional)

This stage uses SonarQube for code testing. If code analysis is not needed, this stage can be skipped.

  1. Click the plus icon to the right of Unit Test to add a stage for performing SonarQube code analysis in a container. Name it Code Analysis.

    code analysis stage

  2. In Code Analysis, click Add Step and select Specify Container. Name it maven and click OK.

    maven container

  3. Click the maven container step and Add nesting steps to add a nesting step. Click WithCredentials and select SonarQube token (sonar-token) from the Credential Name list. Enter SONAR_TOKEN in the Variable and click OK.

    sonarqube credentials

  4. Under the WithCredentials step, click Add nesting steps to add another nesting step.

    nested step

  5. Click WithSonarQubeEnv, enter the name sonar in the pop-up dialog, and click OK to save it.

    sonar env

  6. Under the WithSonarQubeEnv step, click Add nesting steps to add another nesting step.

    add nested step

  7. Click shell and enter the following command in the command line for SonarQube authentication and analysis. Click OK to complete the operation.

    mvn sonar:sonar -Dsonar.login=$SONAR_TOKEN
  8. Click Add nesting steps under the Specify Container step (the third one), select Timeout. Enter 1 in time and choose hours as the unit, then click OK to complete the operation.

    add nested step 2

    timeout set

  9. Click Add nesting steps under the Timeout step, select waitForQualityGate. Check Abort the pipeline if quality gate status is not green in the pop-up dialog. Click OK to save it.

    waitforqualitygate set

    sonar ready

Stage 4: Build and Push Image

  1. Click the plus icon to the right of the previous stage to add a new stage for building and pushing the image to Docker Hub. Name it Build and Push.

  2. In the Build and Push stage, click Add Step, select Specify Container, name it maven, and then click OK.

  3. Click Add nesting steps under the maven container step, select shell from the list, enter the following command in the pop-up window, and click OK to complete the action.

    mvn -Dmaven.test.skip=true clean package
  4. Again, click Add nesting steps, select shell. Enter the following command to build the Docker image based on the Dockerfile.

    docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .
    100%
  5. Once more, click Add nesting steps, select WithCredential. Fill in the following fields in the dialog that appears, and then click OK.

    • Credential Name: Choose the Docker Hub credential you created, for example, dockerhub-id.

    • Username Variable: Enter DOCKER_USERNAME.

    • Password Variable: Enter DOCKER_PASSWORD.

    100%
    Note

    For security reasons, account information is displayed as variables in the script.

  6. In the WithCredential step, click Add nesting steps (the first one). Select shell and enter the following command in the pop-up window to log in to Docker Hub. Click OK to confirm the operation.

    echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin
    100%
  7. In the WithCredential step, click Add nesting steps. Select shell and enter the following command to push the SNAPSHOT image to Docker Hub. Click OK to complete the operation.

    docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER
    100%

Stage 5: Artifacts

  1. Click the plus icon to the right of the Build and Push stage to add a new stage for storing artifacts, name it Artifacts. In this example, a JAR file is used.

    add artifact stage

  2. Select the Artifacts stage, click Add Step, choose Archive artifacts. In the pop-up dialog, enter target/*.jar to set the path for archiving artifacts in Jenkins. Click OK to complete the editing.

    artifact info

Step 4: Run the Pipeline

  1. Pipelines created using the graphical editing panel need to be manually executed. Click Run, and a dialog will appear displaying the three string parameters defined in Step 2: Create a Pipeline. Click OK to run the pipeline.

    run pipeline

  2. Click the Run Records tab to view the running status of the pipeline and click a record to see details.

  3. If the pipeline reaches the Push with Tag stage, it will pause at this stage and require a user with approval permissions to click Proceed.

  4. Log in to the KubeSphere web console as the project-admin user, navigate to Workspace Management, access your DevOps project, and click the graphical-pipeline pipeline. Under the Run Records tab, click the record to be reviewed and click Proceed to approve the pipeline.

Note

To simultaneously run multiple pipelines that do not include multibranch configurations, select these pipelines on the Pipelines list page and click Run to run them in bulk.

Step 5: View Pipeline Details

  1. Log in to the KubeSphere web console as the project-regular user, navigate to Workspace Management, access your DevOps project, and click the graphical-pipeline pipeline.

  2. Under the Run Records tab, click a record under Status to access the details of the run record. If the task status is Successful, all stages of the pipeline will show Successful.

  3. Under the Run Logs tab, click each stage to view detailed logs. Click View Full Logs to troubleshoot and analyze issues based on the logs, which can also be downloaded for further analysis.

Step 6: Download Artifacts

On the Artifacts tab of the run record details page, click the icon next to the artifact to download it.

Step 7: View Code Analysis Results

Navigate to the Code Check page to view the code analysis results provided by SonarQube for this pipeline. This page will be unavailable if SonarQube has not been configured beforehand. For more information, refer to Integrate SonarQube into Pipelines.

Step 8: Verify Kubernetes Resources

If each stage of the pipeline runs successfully, a Docker image will be automatically built and pushed to your Docker Hub repository.

  1. After a successful pipeline run, an image will be pushed to Docker Hub. Log in to Docker Hub to view the result.

    dockerhub image

  2. The application name is APP_NAME, which in this example is devops-sample. The tag value is SNAPSHOT-$BUILD_NUMBER, where $BUILD_NUMBER corresponds to the Run ID listed under the Run Records tab.

Receive the latest news, articles and updates from KubeSphere


Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.