CNB TCA Plugin
Supports triggering code analysis within Cloud Native Build (CNB), providing fast analysis and deep analysis modes.
I. Fast Analysis
Tips
Fast analysis uses default code security analysis rules, requires no analysis scheme configuration, and is ready to use out of the box.
Usage Guide
Copy the following content into the .cnb.yml file to trigger fast analysis in CNB.
# .cnb.yml
"**": # Triggered branch names, default to all branches, can be modified as needed
push: # Triggered by push, can be modified to pull_request, etc.
- stages:
# Get the list of changed git files for TCA incremental analysis
- name: git-change-list
image: cnbcool/git-change-list:latest
settings:
changed: changed.txt # Output the list of changed files to a txt file for subsequent TCA use
# Code analysis
- name: TCA
image: tencentcom/tca-plugin:latest
settings:
from_file: changed.txt # By default, only analyze git changed files; comment out this parameter to analyze all code
block: true # Blocks the pipeline if there are code issues or analysis exceptions. Set to false if pipeline blocking is not desired.
smtp_username: # Optional, email report - sender email address, QQ email recommended
smtp_auth_code: # Optional, email report - mail server authorization code, QQ email authorization code recommended
receiver_email: # Optional, email report - recipient email address
Parameter Description
Tips
The following parameters apply only to the fast analysis scenario.
Core Parameters
| Parameter | Type | Required | Default Value | Description |
|---|---|---|---|---|
| block | bool | No | true | Whether to block the pipeline if there are code issues or analysis exceptions |
| comment | bool | No | true | Whether to add code analysis results to pull_request comments |
| ignore_paths | str list | No | - | Paths to ignore (Unix wildcard format), specify one or more relative workspace paths to exclude. Multiple paths use array format: 1. Match src/test directory: src/test/* 2. Match test directory under root: test/* 3. Match all files ending with _test.py: *_test.py |
| white_paths | str list | No | - | Paths to analyze (Unix wildcard format), specify one or more relative workspace paths to include. Multiple paths use array format |
Email Parameters
To send email reports, configure the following parameters:
| Parameter | Type | Required | Default Value | Description |
|---|---|---|---|---|
| smtp_username | str | Yes | - | Mail server login name (i.e., sender email address, QQ email recommended) |
| smtp_auth_code | str | Yes | - | Mail server authorization code. To avoid exposing the code, configure it in a secret repository and reference it via settingsFrom. |
| receiver_email | str list | Yes | - | Recipient email addresses. Multiple addresses use array format (not limited to QQ email). |
| smtp_host | str | No | smtp.qq.com | Mail server address |
| smtp_port | int | No | 465 | Mail server port |
| cc_receiver_email | str list | No | - | CC recipient email addresses. Multiple addresses use array format |
Viewing Results
Analysis Report
After analysis completes, all issues will be printed in the logs.
After analysis completes,
JSONandHTMLreports will be generated in thetca_reportdirectory of the current workspace for downstream steps:JSON report:
tca_report/tca_report.jsonHTML report:
tca_report/tca_report.html
Email Report
Analysis results can be sent to personal email. Refer to the email parameters above to complete the configuration.
Tips
How to obtain QQ email authorization code: Click here to view.
Merge Request Comments
Code analysis results triggered by pull_request will be automatically added to merge request comments.
II. Deep Analysis
Tips
Deep analysis supports custom analysis schemes, quality gate metrics, and continuous code issue tracking.
Deep analysis requires communication with the TCA platform
Configure the
modeparameter to specifyremote analysis mode nodeorlocal analysis mode local.Default is
node mode, which uses remote nodes to execute code analysis. Analysis tasks will be assigned by the TCA platform to online nodes.Set the
modeparameter tolocalto switch to local analysis mode (data and reports are generated locally and can be freely used).
Usage Guide
First, create a
teamandprojectin TCA (skip if already exists), connect the CNB code repository, configure analysis schemes as needed, and create an analysis project. Refer to Quick Start.After connecting the repository, go to the code repository page, click
Plugin Configurationto enter the TCA plugin configuration dialog, and select theCNB Cloud Native Buildtab.
Tips
Key file addresses refer to steps 3, 4, and 5. If the address already exists, skip the corresponding steps and directly input the key file address into the input box!
Credential information required by the plugin is sensitive personal information; keep it confidential!
Create a new code repository on cnb.cool (select
Key Repositoryas the repository type. Key repositories allow only page viewing and modification, suitable for storing keys for cloud-native builds), e.g.,tca-private-config.
Create a YAML file in the key repository, e.g.,
tca-settings.yml, copy the credential information from the plugin configuration screenshot in step 2 into this file, and commit it. Click to learn File Reference Documentation.Copy the URL of this key file and paste it into the
Key File Addressinput box in the plugin configuration screenshot from step 2. URL example:https://cnb.cool/xxx/tca-private-config/-/blob/main/tca-settings.yml.In the
CNB Cloud Native Buildtab, select the analysis scheme to use. If none exists, create one first. Refer to Analysis Scheme.Click the
Generate .cnb.yml TCA Plugin Configurationbutton, navigate to the root directory of the corresponding repository on cnb.cool, copy the generated configuration content into.cnb.yml(create.cnb.ymlif it does not exist; click Learn More).
(Example only; automatically generate from the plugin configuration on the TCA official website's code repository page.)
# .cnb.yml
"**": # Triggered branch names, default to all branches, can be modified as needed
push: # Triggered by push, or use pull_request, etc.
- docker:
# Declare cache directory, /data/tca_cache/tools is the TCA plugin tool storage directory
volumes:
- /data/tca_cache/tools:copy-on-write
stages:
# Code analysis
- name: TCA
image: tencentcom/tca-plugin:latest
settings:
mode: local # Execution mode; optional values: local (local analysis mode), node (remote node analysis mode); default: node
org_sid: xxx # Team ID (generated from TCA official website; no manual addition required)
team_name: xxx # Project name (generated from TCA official website; no manual addition required)
scheme_id: xxx # Analysis scheme ID (generated from TCA official website; no manual addition required)
settingsFrom:
# Key file reference. Ensure the code repository using this configuration has permission to access the key file; otherwise, the build will fail!
- https://cnb.cool/xxx/tca-private-config/-/blob/main/tca-settings.yml
Parameter Description
Tips
The following parameters apply only to the deep analysis scenario and take precedence over parameters configured on the TCA platform.
Click to view TCA Plugin for the full plugin documentation and related parameters.
Core Parameters
| Parameter | Type | Required | Default Value | Description |
|---|---|---|---|---|
| org_sid | str | Yes | - | Unique team identifier, obtained from the TCA platform |
| team_name | str | Yes | - | Unique project identifier, obtained from the TCA platform |
| scheme_id | str | Yes | - | Analysis scheme ID, obtained from the TCA platform |
| mode | str | No | node | Analysis mode; optional values: local (local analysis mode), node (remote node analysis mode) |
| total_scan | bool | No | false | Whether to perform a full analysis; true for full analysis, false for incremental analysis |
| block | bool | No | true | Whether to block the pipeline if there are quality gate failures or analysis exceptions |
| comment | bool | No | true | Whether to add code analysis results to pull_request comments |
| scan_dir | str | No | - | Analysis directory; defaults to the root directory of the repository to be analyzed. Specify a relative path to define a subdirectory as the analysis directory. |
| ignore_paths | str list | No | - | Paths to ignore (Unix wildcard format), specify one or more relative workspace paths to exclude. Multiple paths use array format: 1. Match src/test directory: src/test/* 2. Match test directory under root: test/* 3. Match all files ending with _test.py: *_test.py |
| white_paths | str list | No | - | Paths to analyze (Unix wildcard format), specify one or more relative workspace paths to include. Multiple paths use array format |
| pre_cmd | str or list | No | - | Pre-command, applicable to compiled analysis tools. Used with compilation commands and executed in the current workspace directory before the compilation command. Multiple pre-commands use array format. |
| build_cmd | str | No | - | Compilation command, applicable to compiled analysis tools. Executed in the current workspace directory. |
Comparison Branch Parameters
| Parameter | Type | Required | Default Value | Description |
|---|---|---|---|---|
| compare_branch | str | No | - | Comparison branch; only analyze incremental issues in the current branch relative to the comparison branch |
Tips
For merge request triggers (MR/PR triggers), this parameter is ignored, and the target branch is automatically used as the comparison branch.
For push triggers, CNB only checks out the current branch. Since the local environment cannot access comparison branch information, incremental analysis may be affected. Therefore, use the
git fetchcommand to pull the comparison branch before the TCA plugin. Below is an example settingcompare_branchtomain:# .cnb.yml feat/dev: # Triggered branch name; modify to the actual branch name push: # Triggered by push - docker: # Declare cache directory, /data/tca_cache/tools is the TCA plugin tool storage directory volumes: - /data/tca_cache/tools:copy-on-write stages: # Pull comparison branch - name: fetch compare branch script: git fetch origin main # Modify `main` to the actual comparison branch name # Code analysis - name: TCA image: tencentcom/tca-plugin:latest settings: mode: local compare_branch: main # Comparison branch name; modify to the actual branch name org_sid: xxx # Team ID, obtained from TCA official website team_name: xxx # Project name, obtained from TCA official website scheme_id: xxx # Analysis scheme ID, obtained from TCA official website total_warning: 0 # Quality gate: total issues (critical + error + warning) ≤ 0 settingsFrom: - https://cnb.cool/xxx/tca-private-config/-/blob/main/tca-settings.yml
Quality Gate Parameters
Tips
Only applicable to
mode: local(local analysis mode only!).When
block: true, the pipeline is blocked if the quality gate fails.For remote analysis mode, configure gate metrics on the TCA platform's
Analysis Scheme - Quality Gatepage.
| Parameter | Type | Required | Description |
|---|---|---|---|
| total_fatal | number | No | Critical issue metric (issue count: critical), requires code inspection. Integer, recommended value: 0 |
| total_error | number | No | Error issue metric (issue count: critical + error), requires code inspection. Integer, recommended value: 0 |
| total_warning | number | No | Warning issue metric (issue count: critical + error + warning), requires code inspection. Integer, recommended value: 0 |
| total_info | number | No | Info issue metric (issue count: critical + error + warning + info), requires code inspection. Integer, recommended value: 0 |
| worse_cc_file_num | number | No | Number of files with increased cyclomatic complexity, requires cyclomatic complexity analysis. Integer, recommended value: 0 |
| duplicate_rate | number | No | Code duplication rate, requires duplicate code analysis. Integer, recommended value: 3 |
Email Parameters
Same as "Fast Analysis - Email Parameters".
Viewing Results
Analysis Report
Directly navigate to the TCA platform to view detailed results.
Local analysis mode only: Data and reports are generated locally. After analysis completes,
JSONandHTMLreports will be output to thetca_reportdirectory of the current workspace for downstream steps:JSON report:
tca_report/tca_report.jsonHTML report:
tca_report/tca_report.html
Email Report
Same as "Fast Analysis - Email Report".
Merge Request Comments
Code analysis results triggered by pull_request will be automatically added to merge request comments.