Code Repositories
Tracking your code and avoiding unnecessary Docker builds by connecting your git repo.
Last updated
Was this helpful?
Tracking your code and avoiding unnecessary Docker builds by connecting your git repo.
Last updated
Was this helpful?
A code repository in ZenML refers to a remote storage location for your code. Some commonly known code repository platforms include and .
Connecting code repositories to ZenML solves two fundamental challenges in machine learning workflows. First, it enhances reproducibility by tracking which specific code version (commit hash) was used for each pipeline run, creating a clear audit trail between your code and its results. Second, it dramatically improves development efficiency by optimizing Docker image building. Instead of including source code in each build, ZenML builds images without the code and downloads it at runtime, eliminating the need to rebuild images after every code change. This not only speeds up individual development cycles but allows team members to share and reuse builds, saving time and computing resources across your organization.
Learn more about how code repositories optimize Docker builds .
If you are planning to use one of the available implementations of code repositories, first, you need to install the corresponding ZenML integration:
Afterward, code repositories can be registered using the CLI:
For concrete options, check out the section on the GitHubCodeRepository
, the GitLabCodeRepository
or how to develop and register a custom code repository implementation.
ZenML comes with builtin implementations of the code repository abstraction for the GitHub
and GitLab
platforms, but it's also possible to use a custom code repository implementation.
ZenML provides built-in support for using GitHub as a code repository for your ZenML pipelines. You can register a GitHub code repository by providing the URL of the GitHub instance, the owner of the repository, the name of the repository, and a GitHub Personal Access Token (PAT) with access to the repository.
Before registering the code repository, first, you have to install the corresponding integration:
Afterward, you can register a GitHub code repository by running the following CLI command:
where <REPOSITORY>
is the name of the code repository you are registering, <OWNER>
is the owner of the repository, <NAME>
is the name of the repository and <GITHUB_TOKEN>
is your GitHub Personal Access Token.
Please refer to the section on using secrets for stack configuration in order to securely store your GitHub Personal Access Token.
After registering the GitHub code repository, ZenML will automatically detect if your source files are being tracked by GitHub and store the commit hash for each pipeline run.
ZenML also provides built-in support for using GitLab as a code repository for your ZenML pipelines. You can register a GitLab code repository by providing the URL of the GitLab project, the group of the project, the name of the project, and a GitLab Personal Access Token (PAT) with access to the project.
Before registering the code repository, first, you have to install the corresponding integration:
Afterward, you can register a GitLab code repository by running the following CLI command:
where <NAME>
is the name of the code repository you are registering, <GROUP>
is the group of the project, <PROJECT>
is the name of the project and <GITLAB_TOKEN>
is your GitLab Personal Access Token.
If you're using a self-hosted GitLab instance, you'll need to also pass the --instance_url=<INSTANCE_URL>
and --host=<HOST>
options. <INSTANCE_URL>
should point to your GitLab instance (defaults to https://gitlab.com/
) and <HOST>
should be the hostname of your GitLab instance (defaults to gitlab.com
).
Please refer to the section on using secrets for stack configuration in order to securely store your GitLab Personal Access Token.
After registering the GitLab code repository, ZenML will automatically detect if your source files are being tracked by GitLab and store the commit hash for each pipeline run.
If you're using some other platform to store your code, and you still want to use a code repository in ZenML, you can implement and register a custom code repository.
First, you'll need to subclass and implement the abstract methods of the zenml.code_repositories.BaseCodeRepository
class:
After you're finished implementing this, you can register it as follows:
If you're using a self-hosted GitHub Enterprise instance, you'll need to also pass the --api_url=<API_URL>
and --host=<HOST>
options. <API_URL>
should point to where the GitHub API is reachable (defaults to https://api.github.com/
) and <HOST>
should be the .
Go to your GitHub account settings and click on .