Integrate MeterSphere into Pipelines
This tutorial demonstrates how to integrate MeterSphere into KubeSphere pipelines.
Prerequisites
- You need to enable the KubeSphere DevOps System.
- You need to deploy MeterSphere on KubeSphere.
- You need to create a workspace, a DevOps project, and an account (
project-regular
). This account needs to be invited to the DevOps project with theoperator
role. If they are not ready, see Create Workspaces, Projects, Accounts and Roles.
Hands-on Lab
Step 1: Create API Keys on MeterSphere
Log in to the MeterSphere console. Go to API Keys under Personal Info and click Create to create API Keys.
You can view the API Keys after they are created. Copy the Access Key.
Click Show under Secret Key to copy the Secret Key.
Step 2: Install MeterSphere plugin on Jenkins
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.
On the Manage Jenkins page, scroll down to Manage Plugins and click it.
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.
After you upload the HPI file, click Upload to continue.
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.
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.
Step 3: Generate a pipeline snippet
Click New Item to create an item.
Set
metersphere-test
for the item name and select Pipeline. Click OK to continue.In this tutorial, click Save directly to use the default settings.
On the Pipeline metersphere-test page, click Pipeline Syntax.
Select metersphere:MeterSphere from the drop-down list of Sample Step under Steps.
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.Note
This tutorial uses the workspace
demo-workspace
and the projectdemo
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.You will see the following output:
Step 4: Create a pipeline
Log in to the web console of KubeSphere as
project-regular
. In your DevOps project, go to Pipelines and then click Create.Set
metersphere-pipeline
for Name and click Create on the Advanced Settings page to use the default configurations.Click the pipeline in the list to go to its detail page and then click Edit Jenkinsfile.
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.
node('base') {
stage('stage-zewwa') {
meterSphere method: 'single',
msAccessKey: 'O4baJHYpybhPizFS',
msEndpoint: 'http://103.61.37.135:31397/',
msSecretKey: 'tIKidlPrpZFJgGl9',
projectId: 'e72714e2-dfc5-4370-a9bc-f17e596caf66',
result: 'jenkins',
testCaseId: '2fc3210b-6c99-4633-9701-1a8941640018',
testPlanId: '',
workspaceId: 'f9dbbadb-0d0c-4d2e-bf6d-0e996d92899d'
}
}
Note
Make sure you change the values of the following fields to the values generated on your Jenkins console:
msAccessKey
,msSecretKey
,msEndpoint
,projectId
,testCaseId
andworkspaceId
.Click Run to run the pipeline.
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.
On the detail page, you can click Show Logs in the upper right corner to view the logs.
You can view the test report on the console of MeterSphere and click it to view its details.