Integrate MeterSphere into Pipelines

This tutorial demonstrates how to integrate MeterSphere into KubeSphere pipelines.

Prerequisites

Hands-on Lab

Step 1: Create API Keys on MeterSphere

  1. Log in to the MeterSphere console. Go to API Keys under Personal Info and click Create to create API Keys.

    create-api-keys

  2. You can view the API Keys after they are created. Copy the Access Key.

    api-key-created

  3. Click Show under Secret Key to copy the Secret Key.

    click-show

    copy-secret-key

Step 2: Install MeterSphere plugin on Jenkins

  1. Log in to the Jenkins console and click Manage Jenkins. For more information about how to log in to the Jenkins console, refer to Integrate SonarQube into Pipelines.

    click-manage-jenkins

  2. On the Manage Jenkins page, scroll down to Manage Plugins and click it.

    click-manage-plugins

  3. Go to the Advanced tab and scroll down to Upload Plugin. Click the button next to Files to upload the HPI file of MeterSphere plugin.

    choose-file

  4. After you upload the HPI file, click Upload to continue.

    click-upload

  5. You can see the installation status on the page and make sure you select Restart Jenkins when installation is complete and no jobs are running. After the installation succeeds, Jenkins will restart.

    installation-success

  6. Once Jenkins finishes restarting, log in and go to Manage Plugins in Manage Jenkins again. On the Installed tab, you can find the MeterSphere plugin just installed.

    installed-tab

    metersphere-in-list

Step 3: Generate a pipeline snippet

  1. Click New Item to create an item.

    click-new-item

  2. Set metersphere-test for the item name and select Pipeline. Click OK to continue.

    set-item-info

  3. In this tutorial, click Save directly to use the default settings.

    click-save

  4. On the Pipeline metersphere-test page, click Pipeline Syntax.

    click-pipeline-syntax

  5. Select metersphere:MeterSphere from the drop-down list of Sample Step under Steps.

    select-metersphere

  6. Input the MeterSphere API Keys created in the above step and the API Endpoint http://NodeIP:NodePort. You can set the rest values from the drop-down lists and then click Generate Pipeline Script.

    input-values

    Note

    This tutorial uses the workspace demo-workspace and the project demo from MeterSphere for demonstration purposes. You need to create workspaces and projects, and configure test cases on MeterSphere first, or there will not be available items from the drop-down lists shown in the above image. For more information about how to use MeterSphere, refer to MeterSphere GitHub website.

  7. You will see the following output:

    snippet-output

Step 4: Create a pipeline

  1. Log in to the web console of KubeSphere as project-regular. In your DevOps project, go to Pipelines and then click Create.

    create-pipeline

  2. Set metersphere-pipeline for Name and click Create on the Advanced Settings page to use the default configurations.

    set-pipeline-name

    click-create-pipeline

  3. Click the pipeline in the list to go to its detail page and then click Edit Jenkinsfile.

    click-pilepine-item

    edit-jenkinsfile

  4. In the dialog that appears, input the following pipeline script based on the snippet generated by Jenkins in the previous step, and then click OK.

    1. node('base') {
    2. stage('stage-zewwa') {
    3. meterSphere method: 'single',
    4. msAccessKey: 'O4baJHYpybhPizFS',
    5. msEndpoint: 'http://103.61.37.135:31397/',
    6. msSecretKey: 'tIKidlPrpZFJgGl9',
    7. projectId: 'e72714e2-dfc5-4370-a9bc-f17e596caf66',
    8. result: 'jenkins',
    9. testCaseId: '2fc3210b-6c99-4633-9701-1a8941640018',
    10. testPlanId: '',
    11. workspaceId: 'f9dbbadb-0d0c-4d2e-bf6d-0e996d92899d'
    12. }
    13. }

    pipeline-script

    Note

    Make sure you change the values of the following fields to the values generated on your Jenkins console: msAccessKey, msSecretKey, msEndpoint, projectId, testCaseId and workspaceId.

  5. Click Run to run the pipeline.

    run-pipeline

  6. Wait for a while and you can see the pipeline reaches the status of Success under the Activity tab. Click it to view its details.

    pipeline-success

  7. On the detail page, you can click Show Logs in the upper right corner to view the logs.

    show-logs

    view-logs

  8. You can view the test report on the console of MeterSphere and click it to view its details.

    test-report

    test-report-detail