Jenkins TCA Plugin
Supports installing the TCA plugin in Jenkins and triggering code analysis via pipelines.
Installation Guide
Go to the
Jenkinspage, navigate toSystem Management -> Plugin Management -> Advanced Settings, upload the downloaded Jenkins TCA Plugin installation package, and deploy it.
Usage Guide
First, create a
TeamandProjectin TCA (skip if already available), and connect to the code repository. For details, 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 theJenkins Pipelinetab.
On the
Jenkins Pipelinetab, select the analysis scheme to use. If none exists, create one first (refer to Analysis Scheme).Click the
Generate Jenkinsfile TCA Plugin Configurationbutton, copy the configuration information, and configure it into theJenkinsfile under the code repositoryorPipeline Scriptas needed:Code Repository Jenkinsfile Configuration
Navigate to the root directory of the code repository, copy the generated configuration content into the
Jenkinsfile(create theJenkinsfileif it does not exist; click Learn More for details). In the pipeline, selectPipeline script from SCM, and set the script path toJenkinsfile.Pipeline Script Configuration
Go to
Jenkins Pipeline, selectPipeline script, copy the generated configuration content into the script, and pull the code repository to be scanned before theCode Analysisstep. Usegitor thecheckoutplugin to download the code.
The plugin is now configured. To adjust parameter configurations, refer to the following example:
pipeline { agent any stages { // Example of pulling code stage ('Pull Code') { steps { git 'https://github.com/xxx.git' } } stage ('Code Analysis') { steps { tca ( // Required parameters scmType: 'git', // Code repository type repoUrl: 'http://xxx', // Code repository URL orgSid: 'xxx', // Team ID (obtain from TCA official website) teamName: 'xxx', // Project name (obtain from TCA official website) schemeID: xxx, // Analysis scheme ID (obtain from TCA official website) token: 'xxx', // Personal credential information (sensitive information, please keep confidential!) // Optional parameters domain: 'xxx', // TCA URL (used for API requests and report link generation; default: https://tca.tencent.com) scanDir: '', // Relative directory to analyze (specify a subdirectory under the code repository as the analysis directory, suitable for analyzing a specific module directory in large repositories; default: scan the root directory of the code repository) revision: '', // Analysis version number (can be set via environment variable '{SCM}_COMMIT' (SCM optional: [GIT])); default: current workspace code version sourceBranch: '', // Branch name (can be set via environment variable '{SCM}_BRANCH' (SCM optional: [GIT])); default: current workspace code branch; required if no branch was specified during code pull targetBranch: '' // Target branch name for comparison (suitable for MR scenarios; can be set via environment variable '{SCM}_TARGET_BRANCH' (SCM optional: [GIT])); default: empty total: false, // Whether to perform a full scan (default: false, i.e., incremental scan) continueOnThresholdNoPass: false, // Do not block subsequent steps if the gate fails (unchecked by default; blocks subsequent steps) // Local analysis parameters localScan: true, // Enable local analysis (unchecked by default; performs node analysis) clientWorkspace: '', // Client workspace (used for local analysis; default: '~/tca_client') preCmd: '', // Pre-command (used when preprocessing is required); default: empty buildCmd: '', // Build command (used when analyzing compiled languages); default: empty exclude: '', // Directories or files to filter (relative paths; multiple paths separated by commas; path format follows Python fnmatch syntax); default: empty include: '' // Directories or files to exclusively analyze (relative paths; multiple paths separated by commas; path format follows Python fnmatch syntax); default: empty ) } } } }Tips
You can extract the
tcastep and write it into any stage of theJenkins Pipelineas needed!Detailed explanation of plugin parameters:
Required parameters and the
domainparameter are automatically generated via the TCA Plugin configuration page.revisionandsourceBranchare obtained from the current workspace's code repository version and source branch using local git commands. If retrieval fails, manually configure them or set them via environment variables.The plugin only blocks the pipeline if execution fails or the gate check fails. Setting
continueOnThresholdNoPassallows the pipeline to proceed even if the gate check fails.localScanenables local analysis, reusing the current pipeline execution environment instead of sending tasks to a resident node. Local analysis parameters only take effect whenlocalScan=true.Local analysis requires downloading the client. Configure
clientWorkspaceas the client directory to reuse the client and avoid time-consuming downloads each time.preCmdandbuildCmdare only used when the analysis scheme is configured with compiled language tools.The default timeout for local analysis is
2h. Set the timeout via the environment variableTCA_LOCAL_TIMEOUT(unit:h).
Local result files:
The plugin generates a result file
tca_report.jsonin the current workspace by default. You can also configure the file path via theTCA_RESULT_FILEenvironment variable. The result file contains the following content:status: success (success)/failure (gate check failed)/error (failure)
status_code: 0 (success)/255 (gate check failed)/1 (failure)
text: Execution status
description: Detailed results
url: Analysis result link
scan_report: Detailed report
lintscan: Code check results
duplicatescan: Code duplication rate results
cyclomaticcomplexityscan: Cyclomatic complexity results
clocscan: Code statistics results
qualityscan: Gate check results