Hui Wu
06/26/2026, 8:02 AMMarvin
06/26/2026, 8:02 AMMarvin
06/26/2026, 8:04 AMflow.from_source(...) / .deploy(...) for Python deployments, or
* use a git_clone pull step in prefect.yaml
* store the token in either:
* a GitLabCredentials block, or
* a Secret block
Best option for private GitLab repos: use `prefect-gitlab`’s GitLabCredentials block.
Docs / references:
* GitRepository reference
* Secret block reference
* prefect-gitlab credentials docs
1) Using a GitLabCredentials block
First install the integration and register blocks if needed:
pip install prefect-gitlab
prefect block register -m prefect_gitlab
Create/save the block:
from prefect_gitlab import GitLabCredentials
creds = GitLabCredentials(token="your-gitlab-token")
creds.save("gitlab-creds")
Then use it with a private repo:
from prefect import flow
from prefect.runner.storage import GitRepository
from prefect_gitlab import GitLabCredentials
@flow
def my_flow():
print("hello")
if __name__ == "__main__":
source = GitRepository(
url="<https://gitlab.com/my-org/my-repo.git>",
credentials=GitLabCredentials.load("gitlab-creds"),
branch="main",
)
my_flow.from_source(
source=source,
entrypoint="flows.py:my_flow",
).deploy(
name="my-deployment",
work_pool_name="my-pool",
)
2) Using a Secret block for the token
If you prefer storing only the token as a secret:
from prefect.blocks.system import Secret
Secret(value="your-gitlab-token").save("gitlab-token")
Then:
from prefect import flow
from prefect.runner.storage import GitRepository
from prefect.blocks.system import Secret
@flow
def my_flow():
print("hello")
if __name__ == "__main__":
source = GitRepository(
url="<https://gitlab.com/my-org/my-repo.git>",
credentials={
"access_token": Secret.load("gitlab-token")
},
branch="main",
)
my_flow.from_source(
source=source,
entrypoint="flows.py:my_flow",
).deploy(
name="my-deployment",
work_pool_name="my-pool",
)
3) If you are using prefect.yaml with a pull step
You can clone from GitLab in the deployment pull step:
pull:
- prefect.deployments.steps.git_clone:
repository: <https://gitlab.com/my-org/my-repo.git>
credentials: "{{ prefect.blocks.gitlab-credentials.gitlab-creds }}"
Or with a Secret block:
pull:
- prefect.deployments.steps.git_clone:
repository: <https://gitlab.com/my-org/my-repo.git>
access_token: "{{ prefect.blocks.secret.gitlab-token }}"
Important note about GitLab CI tokens
If by “GitLab CI token” you mean CI_JOB_TOKEN, that token usually works only within GitLab CI job permissions and repo/project scope. Whether it can clone your target repo depends on your GitLab project settings and token permissions.
If you want to use it dynamically in CI, the simplest pattern is often to expose it as an environment variable and create the Prefect block at deploy time:
from prefect_gitlab import GitLabCredentials
import os
GitLabCredentials(token=os.environ["CI_JOB_TOKEN"]).save(
"gitlab-creds",
overwrite=True
)
Then use GitLabCredentials.load("gitlab-creds").
Important Prefect 3.x note
Old 2.x git storage/block patterns are removed. Don’t use:
* Deployment.build_from_flow()
* prefect deployment build
* old GitHub/Git storage block patterns
Use flow.from_source(...).deploy(...) instead.
If you want, I can give you the exact working example for GitLab CI in one of these cases:
1. deploying from a GitLab CI pipelineMarvin
06/26/2026, 8:04 AMprefect.yaml only