Performing a Check Task with a Third-Party Engine
Scenario
If the check engines provided by CodeArts Check do not meet your requirements, you can use a third-party check engine to execute code check tasks.
Constraints
- To use your custom executors, submit a service ticket.
Resource and Cost Planning
In this practice, you need to purchase an ECS as a custom executor. For details about the price of an ECS, see Price Calculator.
Prerequisites
- You have obtained the code development sample package of the UCCP plug-in. If you need help, submit a service ticket.
- You have purchased an ECS with the EulerOS 7 operating system. The recommended configuration is as follows:
- CPU: 8 vCPUs; memory: 32 GB; system disk: 100 GB; data disk: 250 GB. (If you use this executor specification, you need to attach an EVS disk.)
- CPU: 8 vCPUs; memory: 32 GB; system disk: 250 GB. (If you use this executor specification, you do not need to attach an EVS disk.)
- You have installed Git-LFS on the custom executor. If not, install it by referring to the following command-based example.
# Download wget -O git-lfs.tar.gz https://github.com/git-lfs/git-lfs/releases/download/v3.4.1/git-lfs-linux-amd64-v3.4.1.tar.gz # Decompress tar -zxvf git-lfs.tar.gz # Open the directory generated after the decompression cd git-lfs-3.4.1 # Run the installation script sh install.sh # Verify git lfs version
Process
| No. | Step | Description |
|---|---|---|
| 1 | Create a project. | |
| 2 | Create a pool of custom executors (agent pool). | |
| 3 | Develop the UCCP plug-in to import custom rules. | |
| 4 | Import a third-party engine and plug-in to the executor. | |
| 5 | Upload custom rules to CodeArts Check. | |
| 6 | Create a repository to store code. | |
| 7 | Create a code check task. | |
| 8 | Configure the task to use the custom executor and rules. | |
| 9 | View check results. |
Creating a Project
- Log in to the Huawei Cloud console.
- Click
in the upper left corner and choose from the service list. - Click Go to CodeArts Check to go to the CodeArts Check homepage.
- In the navigation pane, choose Homepage. Click Create > Create Project, and select the Scrum template.
- Enter the project name, for example, check-bestpractice. Retain the other parameters as default.
- Click OK to access the project.
Creating an Agent Pool
- On the navigation bar, click the username
and choose All Account Settings. - Choose .
- Click Create Pool. In the displayed dialog box, set parameters according to Table 2 and click Save.
Table 2 Agent pool configuration Parameter
Description
Pool Name
Assign a custom name to the pool, for example, custom_pool.
Pool Type
Select LINUX_DOCKER. When a task is initiated, a Linux Docker container will be started to run the task.
Description
(Optional) Enter additional information to describe the pool.
This pool can be used by all users of the current account.
(Optional) Selecting this option allows all users within the current account to use the pool.
- Click the name of the new pool (custom_pool is used in this practice). The pool configuration page is displayed.
- Click Create Agent. In the displayed dialog box, configure the agent according to Table 3 and leave the other parameters as default.
Table 3 Parameters for creating an agent Parameter
Description
Install Docker
Selecting this option requires Docker installation.
Install Docker automatically
Toggling on the switch will automatically install Docker.
AK
SK
Agent Name
Assign a custom name to the agent, for example, agent_test_custom.
Agent Workspace
Enter an agent workspace that follows the standard Linux directory structure. For example, /opt/agent_test_custom.
- Select the check box to confirm that you have read and accept the agreements. Then click Generate Command and Copy Command. Click Close.
- Go to the ECS list page, find the row of the ECS purchased to meet prerequisites, click Remote Login, and run the command copied in 6, as instructed by Step 3.
- On the agent list page, click Refresh List. After the information is automatically synchronized in the background, a new item will be added to the list. The agent alias is agent_test_custom-mwlye1NlLG.
Developing a UCCP Plug-in
- Decompress the PluginExtensionPointDemo.zip package obtained in Prerequisites to a local path.
- Find pom.xml in the project root directory and change <plugin.name>DemoEngine</plugin.name> to the new engine name <plugin.name>cmetrics</plugin.name>.
- Find the ThirdPartyToolsPlugin.java class and change the variable to the new engine name mentioned in 2, for example, CmetricsToolsPlugin.
Ensure that the constructor name is the same as the file name.
- Modify the settings file to enable external downloading of dependencies from the repository.
- Implement the execute method in CmetricsToolsPlugin.
The following figure shows the input parameters.
Return a defect list file. The following figure shows the defect fields.
- You are advised to invoke the engine script in the execute method so that the engine can generate the defect list file.
Importing a Third-Party Engine and Plug-in to the Executor
- Run the following command in the /opt/cloud/ directory on the executor to create the third_party_tools/v1/plugins directory:
mkdir -p /opt/cloud/third_party_tools/v1/plugins
- On the executor, save the developed UCCP plug-in to the /opt/cloud/third_party_tools/v1/plugins path. Then, run the following commands to change the permission:
chmod -R 777 [Path of the package to be replaced] & chown -R slave1:slave1 [Path of the package to be replaced] &
- Save the tool package to the /opt/cloud/third_party_tools/v1/tools path. Then, run the following commands to change the permission:
chmod -R 777 [Path of the package to be replaced] & chown -R slave1:slave1 [Path of the package to be replaced] &
v1 in the preceding plug-in and tool paths indicates the version number. Multiple versions can coexist, for example, /opt/cloud/third_party_tools/v1/plugins, /opt/cloud/third_party_tools/v2/plugins and /opt/cloud/third_party_tools/v3/plugins. When executing a task, the system selects the latest version number. For example, the plug-in stored in /opt/cloud/third_party_tools/v3/plugins is select to execute the task. This rule also applies to tools.
Uploading Custom Rules
- On the CodeArts Check homepage, click the Rules tab, click Create Rule, and select Import Rules.
You can import rules of any engine and any language.
- Use the provided table templates to enter your rule information.
- After the import is successful, choose System Rules > Custom in the navigation pane on the left to view the rules imported in 1.
Custom rules can be edited and deleted by the creator. You can click the Manage tab to modify the rule information or delete the rule.
Creating a Code Repository in CodeArts Repo
- In the navigation pane, choose . The CodeArts Repo homepage is displayed.
- On the CodeArts Repo homepage, click Create Repository.
- On the displayed page, select Template.
- Click Next and select the Java Maven Demo template.
- Click Next. Set the repository name to custom_repo and deselect Automatically create check task. Retain the default values for other parameters.
- Click OK.
shows the directory that stores files of the code repository.
Creating a Check Task
- On the CodeArts Check task list page, click Create Task and configure parameters by referring to Table 4.
Table 4 Task parameters Parameter
Description
Project
Retain the default value (the check-bestpractice project created in Creating a Project).
Code Source
Source of code. Select Repo.
Name
Enter a task name, for example, CheckTask01.
Repository
Select custom_repo, the code repository created in Creating a Code Repository in CodeArts Repo.
Branch
Retain the default value master.
Language
Select Java.
- Click Confirm.
Creating a Custom Rule Set
- On the task list, click the Rule Sets tab.
- Click Create Rule Set. In the displayed window, set Rule Set to RuleList and Language to JAVA.
- Click OK.
- Select the rules mentioned in Uploading Custom Rules and click Save in the upper right corner.
Configuring a Code Check Task
- On the Tasks page, click the task name.
- Click Settings.
- Click Rule Sets. In the right pane, click
to select the RuleList rule set created in Creating a Custom Rule Set. - Click Execute Check in the upper right corner.
Viewing Check Results
- On the Tasks page, search for the CheckTask01 task created in Creating a Check Task.
- Click the task name to view the check details, including overview, issues, metrics, logs, and settings.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot