Skip to main content

!git.repository

The !git.repository Atmos YAML function returns the repository slug of the current Git repository in <owner>/<name> form (for example, cloudposse/atmos) — the same format as GitHub's GITHUB_REPOSITORY environment variable. The value is derived from the origin remote URL and works for GitHub, GitLab, Bitbucket, and Azure DevOps.

Usage

# Get the repository slug (`<owner>/<name>`).
# If the repository cannot be resolved, it returns a default value if specified; otherwise, it returns an error.
!git.repository <default-value>

Examples

vars:
# Tag resources with the repository that produced the plan.
git_repo: !git.repository
vars:
# Fall back to a literal value when there is no remote (e.g. a fresh checkout).
git_repo: !git.repository my-org/my-repo

Composing with other values

A YAML tag owns the entire scalar, so you cannot combine !git.repository with additional text on the same line (e.g. "!git.repository/{{ ... }}" is not valid). Atmos also evaluates Go templates before YAML functions, so referencing !git.repository through an intermediate variable in a plain template does not work either.

To compose the slug with a path segment in a single value — for example, prefixing a workspace_key_prefix — use the atmos.Resolve template function, which evaluates a YAML function at template-render time:

settings:
context:
repo: "!git.repository"
components:
terraform:
vpc:
backend:
s3:
workspace_key_prefix: '{{ atmos.Resolve .settings.context.repo }}/{{ or .metadata.name .metadata.component }}'