Skip to main content

CODEOWNERS

Ensure that a project has a valid CODEOWNERS file. On the default branch, 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, email addresses, and role owners are eligible for the project.

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.

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. On other protected refs, the job validates the file without writing it.

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​

NameDescriptionDefaultType
------------
check-pathsRequire every non-exclusion CODEOWNERS path pattern to match a tracked file.trueboolean
codeownersCODEOWNERS file content written to the default branch.# Specify Code Owners, read more at https://docs.gitlab.com/user/project/codeowners/ [Default] * @@maintainer @@owner string
nameName of the CODEOWNERS job.projectstring
needsJobs required before validation.[]array
overrideReplace an existing CODEOWNERS file when its content differs.trueboolean
pathRepository-relative CODEOWNERS path to ensure and validate.CODEOWNERSstring
refRepository branch or tag containing the CODEOWNERS file.$CI_COMMIT_REF_NAMEstring
rulesRules controlling when CODEOWNERS validation runs.[{"if":"$CI_COMMIT_REF_PROTECTED == \"true\"","when":"on_success"}]array
stageStage where CODEOWNERS validation runs.lintstring
tagsRunner tags for the validation job.[]array
timeoutGitLab API timeout in seconds.30number
token-variableProtected CI/CD variable containing a GitLab token with api scope.GITLAB_TOKENstring