Badges
About 2153 wordsAbout 7 min
Badges display metric data, using color to indicate whether standards are met.
When to use: when you want build status visible at a glance on a repository homepage or an external page — for example embedding build status or test coverage badges in a README.
Cloud Native Build Related Badges
Badge Access Path
Badge access paths for cloud native builds:
precise:
https://cnb.build/{group}/{repository}/-/badge/git/{sha}/{metrics}latest:
https://cnb.build/{group}/{repository}/-/badge/git/latest/{metrics}branch latest:
https://cnb.build/{group}/{repository}/-/badge/git/latest/{metrics}?branch={branch}Parameter descriptions:
group: Organization path of the repositoryrepository: Repository namesha: First 8 characters of the CommitIdlatest: When branch is not specified, fetches the badge for the latest default branch commit; when specified, fetches the badge for the latest commit of that branchmetrics: Metric name, e.g.,ci/status/push, representing the build time triggered by push eventsbranch: Branch name, e.g.,main, only effective when sha islatest
Badge Types
During cloud native builds, badge data for build metrics is automatically reported:
1. Git Events
ci/status/push
Push event build time and status
ci/status/commit.add
Commit add event build time and status
ci/status/branch.create
Branch create event build time and status
ci/status/pull_request
Pull request event build time and status
ci/status/pull_request.update
Pull request update event build time and status
ci/status/pull_request.target
Pull request target event build time and status
ci/status/pull_request.merged
Pull request merged event build time and status
ci/status/pull_request.approved
Pull request approved event build time and status
ci/status/pull_request.changes_requested
Pull request changes requested event build time and status
ci/status/pull_request.mergeable
Pull request mergeable event build time and status
ci/status/issue.comment@npc
Issue comment @npc event build time and status
ci/status/pull_request.comment@npc
Pull request comment @npc event build time and status
ci/status/tag_push
Tag push event build time and status
2. Workspace Preparation
ci/git-clone-yyds
Workspace size and preparation time:
3. Pipeline Configuration
ci/pipeline-as-code
Cloud native build configuration file:
4. Cloud Native Development
code/vscode-started
Development environment preparation time:
5. Unit Testing
Using the built-in task testing:coverage can report unit test badge data
testing/unit/coverage
Total unit test coverage
testing/unit/coverage-pr
Incremental unit test coverage for this pull request
6. Security
security/tca
Tencent Cloud Code Analysis (TCA):
7. Crontab Status
ci/status/crontab
Crontab build duration and build status
8. Auto Merge
ci/status/auto_merge
Auto merge duration and status
Repository Related Badges
Fork Badge
Display repository fork count as a badge:
Access path: https://cnb.build/{group}/{repository}/-/badge/fork
Parameter descriptions:
group: Repository organization pathrepository: Repository name
Star Badge
Display repository star count as a badge:
Access path: https://cnb.build/{group}/{repository}/-/badge/star
Parameter meanings:
group: Repository organization pathrepository: Repository name
Deploy Badge
Display the latest deployment status and version of a repository environment:
- With successful deployment:
- Without deployment record:
Access path: https://cnb.build/{group}/{repository}/-/badge/deploy?name={name}
Click-through path: https://cnb.build/{group}/{repository}/-/badge/deploy.link?name={name}
Parameter descriptions:
group: Repository organization pathrepository: Repository namename: Deployment environment name (required), e.g.,production,staging, etc.
Release Badge
Display the latest Release version of the repository. If a Release tag has been manually set as the Latest Release, the badge prioritizes that Release; otherwise, it defaults to the most recently created Release:
- With Release:
- Without Release:
Access path: https://cnb.build/{group}/{repository}/-/badge/release
Click-through path: https://cnb.build/{group}/{repository}/-/badge/release.link
Parameter descriptions:
group: Repository organization pathrepository: Repository name
Metadata Badge
Display the value of repository metadata.
Metadata is stored as key-value pairs attached to a commit or tag. The badge label is the metadata key, and the badge message is the metadata value.
- Metadata found:
- Metadata not found:
Access Path
Commit metadata badge:
# Specific commit
https://cnb.build/{group}/{repository}/-/badge/annotation/commit/{sha}/{key}
# Latest commit of the default branch
https://cnb.build/{group}/{repository}/-/badge/annotation/commit/latest/{key}
# Latest commit of a specific branch
https://cnb.build/{group}/{repository}/-/badge/annotation/commit/latest/{key}?branch={branch}Tag metadata badge:
https://cnb.build/{group}/{repository}/-/badge/annotation/tag/{tag}/{key}Parameter Descriptions
group: Repository organization pathrepository: Repository namesha: Full commit hashlatest: Get the metadata of the latest commit of a branch; the default branch is used whenbranchis omittedtag: Tag name,/is supported; URL-encode it when it contains special characterskey: Metadata key, e.g.,reviewer; only letters, digits,_and-are allowed, up to 64 charactersbranch: Branch name, e.g.,main, only effective when ref islatest
Extensions
Append an extension after {key} to get different content:
- No extension: returns an SVG badge
{key}.json: returns the badge data as JSON{key}.link: 302 redirects to the corresponding commit or tag detail page
Color Rules
- The badge message color is derived from the metadata
keyin a stable way - The same key always gets the same color, and different keys pick colors from a dedicated palette
- When the metadata is not found, the message is
unknownand the color is grey
Security Metadata Badge
Display security scan results. The badge label is the plugin name, the message lists the issue count of each level, and the color is determined by the most severe level:
security badge security badge
Access Path
# Specific commit
https://cnb.build/{group}/{repository}/-/badge/security/{plugin}/{scope}/{sha}
# Latest commit of the default branch
https://cnb.build/{group}/{repository}/-/badge/security/{plugin}/{scope}/latest
# Latest commit of a specific branch
https://cnb.build/{group}/{repository}/-/badge/security/{plugin}/{scope}/latest?branch={branch}Parameter Descriptions
group: Repository organization pathrepository: Repository namesha: Full commit hashlatest: Get the security metadata of the latest commit of a branch; the default branch is used whenbranchis omittedplugin: Plugin name, only the following three values are supported. See Security Scan Plugins for detailsvulnerability: Open-Source Component Vulnerability Scanlicense: License Scansbom: SBOM Generation
scope: Statistics scope,fullordiffbranch: Branch name, e.g.,main, only effective when ref islatest
Security metadata is only attached to commits, so the ref currently only supports a full commit hash or latest.
Extensions
- No extension: returns an SVG badge
{sha}.json/latest.json: returns the badge data as JSON, including the issue count of each level{sha}.link/latest.link: 302 redirects to the security scan report
Badge List
vulnerability/full
Full result of the Open-Source Component Vulnerability Scan, showing the vulnerability count of each severity level.
vulnerability/diff
Incremental result of the Open-Source Component Vulnerability Scan, counting only the vulnerabilities introduced by the current change.
license/full
Full result of the License Scan, showing the license count of each risk level.
license/diff
Incremental result of the License Scan, counting only the license risks introduced by the current change.
sbom/full
Full result of the SBOM Generation, showing the total component count of the current Commit.
sbom/diff
Incremental result of the SBOM Generation, showing the number of components involved in the current change.
Using Badges in Markdown
Two formats are supported for embedding badges as images in Markdown:
With domain and repository: 
Without domain and repository: paths starting with /-/badge/git will be recognized as badges: 
Embedding Badges in a README
The example below puts the latest main branch build status and unit test coverage badges at the top of the repository README, and links each badge back to the repository home page (replace groupname/reponame with the actual organization and repository name):
# Project name
[](
https://cnb.build/groupname/reponame)
[](
https://cnb.build/groupname/reponame)
Project introduction…- To pin a badge to a specific commit, replace
latestwith the first 8 characters of that commit'ssha. - To show a badge for another branch, append
?branch=<branch-name>to the URL. - The unit test coverage badge requires data reported by the testing:coverage built-in task.
Tips
The relative form without a domain (/-/badge/git/...) only works in Markdown rendered inside the platform. When the README is displayed on a third-party platform such as GitHub, use the full path with domain and repository.