CODEOWNERS
Ensure that a project has a valid CODEOWNERS file. By default, the
component creates the file or updates it when the configured content differs.
It then checks GitLab syntax, verifies that path patterns match tracked files,
and confirms that referenced users, groups, group aliases, and email addresses
are eligible for the project. Role owners (@@developer, @@maintainer, and
@@owner, including their plural forms) are checked for valid syntax only;
they do not require a current direct project member with that role. GitLab
resolves role-based ownership when it evaluates a merge request.
Store a token with api scope in a protected, masked CI/CD variable named
GITLAB_TOKEN. The token must be allowed to commit to the default branch and
read the project, its eligible users and groups, and member email addresses when
email owners are used.
The job reports errors but does not block the pipeline by default, as ownership
bootstrap is advisory. Set allow-failure: false to make it required. Errors
remain visible in the job log and as a pipeline warning; they are not discarded.
There is no automatic job-token fallback for API writes. GitLab job tokens do
not support creating repository files through the Files API. Git pushes using a
job token require an explicit project setting and appropriate branch permission;
they do not provide the API access needed for owner validation. Keep using the
configured API token rather than substituting CI_JOB_TOKEN.
Add default ownership
Include the component in .gitlab-ci.yml:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/codeowners@stable
The first default-branch pipeline writes this file to CODEOWNERS:
# Specify Code Owners, read more at https://docs.gitlab.com/user/project/codeowners/
[Default]
* @@maintainer @@owner
The API commit starts another default-branch pipeline. That pipeline finds the same content and does not create another commit.
The default ref is $CI_DEFAULT_BRANCH, including in tag pipelines where
CI_COMMIT_BRANCH is empty. The job writes before validating the effective
content, even when the checkout predates the generated file. Set ref to another
branch or tag to validate it without writing to that ref.
Configure ownership
Set codeowners to the complete file content. Set path to use
docs/CODEOWNERS or .gitlab/CODEOWNERS instead of the repository root.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/codeowners@stable
inputs:
codeowners: |
/docs/ @documentation
/src/ @application-team
path: .gitlab/CODEOWNERS
The default override: true updates an existing file when it differs. Set
override: false to preserve existing content and only create a missing file.
The preserved file is still validated.
Set token-variable to use a differently named CI/CD variable. Set
check-paths: false when intentionally declaring ownership for files that do
not exist yet.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| allow-failure | Report CODEOWNERS errors without blocking the pipeline. | true | boolean |
| check-paths | Require every non-exclusion CODEOWNERS path pattern to match a tracked file. | true | boolean |
| codeowners | CODEOWNERS file content written to the default branch. | # Specify Code Owners, read more at https://docs.gitlab.com/user/project/codeowners/ [Default] * @@maintainer @@owner | string |
| name | Name of the CODEOWNERS job. | project | string |
| needs | Jobs required before validation. | [] | array |
| override | Replace an existing CODEOWNERS file when its content differs. | true | boolean |
| path | Repository-relative CODEOWNERS path to ensure and validate. | CODEOWNERS | string |
| ref | Repository branch or tag containing the CODEOWNERS file. | $CI_DEFAULT_BRANCH | string |
| rules | Rules controlling when CODEOWNERS validation runs. | [{"if":"$CI_COMMIT_REF_PROTECTED == \"true\"","when":"on_success"}] | array |
| stage | Stage where CODEOWNERS validation runs. | lint | string |
| tags | Runner tags for the validation job. | [] | array |
| timeout | GitLab API timeout in seconds. | 30 | number |
| token-variable | Protected CI/CD variable containing a GitLab token with api scope. | GITLAB_TOKEN | string |