Version control your dbt Cloud jobs with YML.
Project description
dbt-cloud-jobs
Version control your dbt Cloud jobs with YML.
Installation
pip install dbt-cloud-jobs
Quickstart
-
Create an API token in dbt Cloud:
- Generate a service account token, make sure to grant the
Jobs Adminpermission set. - If you do not have access to create a service account token you can create a User API token. Note that the service account method is preferred.
- Generate a service account token, make sure to grant the
-
Set an environment variable with the value of the token:
export DBT_API_TOKEN="<VALUE_FROM_PREVIOUS_STEP>"
-
Set an environment variable for the region where your dbt Cloud account is hosted. The value must be one of "AU", "Europe" or "US" (see docs here):
export DBT_CLOUD_REGION="<REGION>"
-
Import your existing dbt Cloud jobs:
dbt_cloud_jobs --import --account-id 123456 --file dbt_cloud_jobs.yml
-
Edit the definition of your jobs in
dbt_cloud_jobs.yml. -
Sync the updated definitions to dbt Cloud:
dbt_cloud_jobs --sync --file dbt_cloud_jobs.yml
Recommended usage in CI/CD
CI
In CI dbt-cloud-jobs should be used to verify that the provided YML file is valid. For example:
- name: Install dbt_cloud_jobs
run: pip install dbt-cloud-jobs
- name: Validate `dbt_cloud_jobs.yml`
run: dbt_cloud_jobs --validate --file dbt_cloud_jobs.yml
CD
In CD dbt-cloud-jobs should be used to sync the provided YML file to dbt Cloud. For example:
- name: Install dbt_cloud_jobs
run: pip install dbt-cloud-jobs
- name: Sync `dbt_cloud_jobs.yml`
run: dbt_cloud_jobs --sync --file dbt_cloud_jobs.yml
Example
For an example of how this package can be used, take a look at dbt-cloud-jobs-example-repo, specifically:
- The
dbt_cloud_jobs.ymlfile. - The CI pipeline.
- The CD pipeline.
- This CI pipeline run that validated the jobs definitions added in PR1.
- This CD pipeline run that updated the
Daily jobdbt Cloud job.
Limitations/Warnings
-
Service account tokens are created at the account level. This means that if you have multiple dbt Cloud accounts you will need to create different
dbt_cloud_jobs.ymlfiles for each account. If you try to usedbt-cloud-jobswith a file that contains multipleaccount_idvalues, an error will be raised. -
⚠️
dbt_cloud_jobsexpects to "own" all the jobs in the projects where it is used. This means that if you are runningdbt_cloud_jobs --sync --file dbt_cloud_jobs.ymlfor the first time in a project, any pre-existing jobs not present in yourdbt_cloud_jobs.ymlfile will be deleted.
Development
To setup your development environment, fork this repository and run:
poetry shell
poetry install
Set the following environment variables:
export DBT_ACCOUNT_ID=<DBT_ACCOUNT_ID>
export DBT_CLOUD_REGION="<DBT_CLOUD_REGION>"
export DBT_ENVIRONMENT_ID=<DBT_ENVIRONMENT_ID>
export DBT_PROJECT_ID=<DBT_PROJECT_ID>
export DBT_API_TOKEN="<DBT_API_TOKEN>"
It is highly recommended that a dedicated dbt Cloud environment be used for development.
All tests can be run via:
make test
Release
Trigger the Publish to PyPi workflow, inputting the version to publish to PyPi. This workflow will:
- Publish the version to PyPi.
- Tag the HEAD commit of the
mainbranches (tags visible here). - Create a release (releases visible here).
Publications
- This repo formed part of a talk at Coalesce 2024: Empowering dbt developers: Self-serve dbt Cloud jobs from your dbt repo, slides
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_cloud_jobs-0.2.0.tar.gz.
File metadata
- Download URL: dbt_cloud_jobs-0.2.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b36e012be1033ed94ca514e875e32619651b46493b25f09bef6c6f990ccbb245
|
|
| MD5 |
4f1270e81851fc8dda6a74c10fba77cd
|
|
| BLAKE2b-256 |
94d567f413b59acfea139f560be0bf94387b2e5a83f39761acbf13737eea17cc
|
Provenance
The following attestation bundles were made for dbt_cloud_jobs-0.2.0.tar.gz:
Publisher:
publish.yml on pgoslatara/dbt-cloud-jobs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbt_cloud_jobs-0.2.0.tar.gz -
Subject digest:
b36e012be1033ed94ca514e875e32619651b46493b25f09bef6c6f990ccbb245 - Sigstore transparency entry: 162088560
- Sigstore integration time:
-
Permalink:
pgoslatara/dbt-cloud-jobs@4b6669710e789c9895934af0b9e62873b8110f12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pgoslatara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b6669710e789c9895934af0b9e62873b8110f12 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dbt_cloud_jobs-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dbt_cloud_jobs-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c1a54dd1cb54f6c1439ba00c1d64d9a6e648bb0b3152cf2310df5321044b01c
|
|
| MD5 |
f23f880ef87219f0e39e04104a3fa270
|
|
| BLAKE2b-256 |
da6b61f32e3f561ffc1cdddd5f6f067650599ce6f17821c8950f7f51ac562429
|
Provenance
The following attestation bundles were made for dbt_cloud_jobs-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on pgoslatara/dbt-cloud-jobs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbt_cloud_jobs-0.2.0-py3-none-any.whl -
Subject digest:
5c1a54dd1cb54f6c1439ba00c1d64d9a6e648bb0b3152cf2310df5321044b01c - Sigstore transparency entry: 162088562
- Sigstore integration time:
-
Permalink:
pgoslatara/dbt-cloud-jobs@4b6669710e789c9895934af0b9e62873b8110f12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pgoslatara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b6669710e789c9895934af0b9e62873b8110f12 -
Trigger Event:
workflow_dispatch
-
Statement type: