debian-mirror-gitlab/doc/user/project/badges.md

98 lines
4.1 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference, howto
---
2021-03-11 19:13:27 +05:30
# Badges **(FREE)**
2018-05-09 12:01:36 +05:30
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41174) in GitLab 10.7.
2018-05-09 12:01:36 +05:30
Badges are a unified way to present condensed pieces of information about your
2021-01-03 14:25:43 +05:30
projects. They consist of a small image and a URL that the image
2020-04-22 19:07:51 +05:30
points to. Examples for badges can be the [pipeline status](../../ci/pipelines/settings.md#pipeline-status-badge),
[test coverage](../../ci/pipelines/settings.md#test-coverage-report-badge), or ways to contact the
project maintainers.
2018-05-09 12:01:36 +05:30
![Badges on Project overview page](img/project_overview_badges.png)
## Project badges
2020-04-08 14:13:33 +05:30
Badges can be added to a project by Maintainers or Owners, and will then be visible on the project's overview page.
2018-05-09 12:01:36 +05:30
If you find that you have to add the same badges to several projects, you may want to add them at the [group level](#group-badges).
To add a new badge to a project:
2019-10-12 21:52:04 +05:30
1. Navigate to your project's **Settings > General > Badges**.
1. Under "Link", enter the URL that the badges should point to and under
"Badge image URL" the URL of the image that should be displayed.
1. Submit the badge by clicking the **Add badge** button.
2018-05-09 12:01:36 +05:30
After adding a badge to a project, you can see it in the list below the form.
You can edit it by clicking on the pen icon next to it or to delete it by
clicking on the trash icon.
Badges associated with a group can only be edited or deleted on the
[group level](#group-badges).
2020-10-24 23:57:45 +05:30
### Example project badge: Pipeline Status
A common project badge presents the GitLab CI pipeline status.
To add this badge to a project:
1. Navigate to your project's **Settings > General > Badges**.
1. Under **Name**, enter _Pipeline Status_.
1. Under **Link**, enter the following URL:
`https://gitlab.com/%{project_path}/-/commits/%{default_branch}`
1. Under **Badge image URL**, enter the following URL:
`https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg`
1. Submit the badge by clicking the **Add badge** button.
2018-05-09 12:01:36 +05:30
## Group badges
Badges can be added to a group and will then be visible on every project's
overview page that's under that group. In this case, they cannot be edited or
deleted on the project level. If you need to have individual badges for each
project, consider adding them on the [project level](#project-badges) or use
[placeholders](#placeholders).
To add a new badge to a group:
2019-10-12 21:52:04 +05:30
1. Navigate to your group's **Settings > General > Badges**.
1. Under "Link", enter the URL that the badges should point to and under
"Badge image URL" the URL of the image that should be displayed.
1. Submit the badge by clicking the **Add badge** button.
2018-05-09 12:01:36 +05:30
After adding a badge to a group, you can see it in the list below the form.
You can edit the badge by clicking on the pen icon next to it or to delete it
by clicking on the trash icon.
Badges directly associated with a project can be configured on the
[project level](#project-badges).
## Placeholders
The URL a badge points to, as well as the image URL, can contain placeholders
which will be evaluated when displaying the badge. The following placeholders
are available:
- `%{project_path}`: Path of a project including the parent groups
- `%{project_id}`: Database ID associated with a project
- `%{default_branch}`: Default branch name configured for a project's repository
- `%{commit_sha}`: ID of the most recent commit to the default branch of a
project's repository
2021-02-22 17:27:13 +05:30
NOTE:
2019-07-07 11:18:12 +05:30
Placeholders allow badges to expose otherwise-private information, such as the
default branch or commit SHA when the project is configured to have a private
repository. This is by design, as badges are intended to be used publicly. Avoid
using these placeholders if the information is sensitive.
2018-05-09 12:01:36 +05:30
## API
You can also configure badges via the GitLab API. As in the settings, there is
a distinction between endpoints for badges on the
[project level](../../api/project_badges.md) and [group level](../../api/group_badges.md).