Sub topic 16
Running jobs from a Git source
This chapter assumes you can create a basic job in the Databricks Jobs UI. It also assumes you have a Git credential saved for your user (see the credentials chapter) and know that a notebook accepts parameters through widgets. By the end you will be able to configure a job whose code comes from a Git repository instead of the workspace, pin it to a version, and diagnose the common failures.
Two places a job can read code from
A notebook task has a source, which says where the notebook file lives.
- Workspace: the job runs the notebook at a workspace path. If that path is inside a Git folder, the job runs whatever is currently checked out there, including uncommitted edits.
- Git provider: the job stores a repository URL and a reference. At the start of each run, Databricks fetches that reference and runs the notebook from the fetched copy. No Git folder is involved.
| Aspect | Workspace source | Git source |
|---|---|---|
| What runs | Current state of the workspace path | Contents of a branch, tag, or commit |
| Uncommitted edits | Run, if the path is in a Git folder | Never run |
| Reproducibility | Depends on who last pulled or edited | Fixed by a tag or commit |
| Path format | Absolute workspace path | Path relative to the repository root |
| Needs a Git folder | No, but common | No |
Git source is the safer choice for production. The job can only run code that has been committed and pushed, so a half-finished edit in someone's Git folder cannot reach it.
What happens at run time
Each run starts by resolving the reference to a commit. A branch resolves to its latest commit at that moment. A tag or a commit SHA resolves to the same commit every time. The job then runs every task from that single commit, so a push during a run does not change the code halfway through.
Configuring it in the UI
When you add or edit a notebook task:
- Set Source to Git provider.
- Choose Edit or Add a git reference. Enter the repository URL and pick the provider, such as GitHub or Azure DevOps.
- Choose the reference type (Branch, Tag, or Commit) and enter its name or SHA.
- Enter the Path relative to the repository root, for example
notebooks/daily_load. Do not start with a slash. Leave off the file extension for notebooks.
The Git reference belongs to the job, not to each task. All tasks in the job share one repository and one reference.
Configuring it as code
The same setup in the Jobs API is a git_source block plus "source": "GIT" on each task. Save this as job.json:
{
"name": "daily-load",
"git_source": {
"git_url": "https://github.com/example-org/orders-pipeline",
"git_provider": "gitHub",
"git_tag": "v1.4.0"
},
"tasks": [
{
"task_key": "load",
"notebook_task": {
"notebook_path": "notebooks/daily_load",
"source": "GIT",
"base_parameters": {
"run_date": "2026-01-01"
}
},
"job_cluster_key": "main"
}
],
"job_clusters": [
{
"job_cluster_key": "main",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 2
}
}
]
}Create it with the Databricks CLI:
databricks jobs create --json @job.jsonTo pin to a branch, replace git_tag with "git_branch": "main". To pin to an exact commit, use "git_commit": "<full SHA>". Set only one of the three. The node_type_id and spark_version values depend on your cloud and workspace, so substitute values your workspace offers.
Parameters reach the notebook as widgets
The base_parameters map sets widget values. The notebook from the widgets chapter works unchanged:
dbutils.widgets.text("run_date", "2026-01-01", "Run date")
run_date = dbutils.widgets.get("run_date")
print(f"Processing {run_date}")The widget default in the notebook applies only when the job supplies no value. A parameter name that has no matching widget is not an error, but the notebook ignores it. A typo in either place therefore shows up as the default date being used, with no failure.
You can override parameters for a single run without editing the job. In the UI, use Run now with different parameters. This is useful for backfills, where you rerun the same pinned code with a different run_date.
Choosing a reference
| Reference | Behavior | Use it when |
|---|---|---|
| Branch | Moves with each push | Development and staging jobs that should follow the latest code |
| Tag | Fixed unless someone moves the tag | Production releases you want to name and roll back |
| Commit | Fixed forever | Audits or reproducing a past result exactly |
A common pattern is two jobs from one repository. A staging job follows main. A production job follows a release tag that you update only after staging passes.
Credentials and run-as identity
For a private repository, the run needs a credential to fetch the code. Databricks uses the Git credential of the identity the job runs as. If you run the job as a service principal, that service principal needs its own Git credential. Your personal credential does not transfer to it. A scheduled job that worked while you owned it can start failing after the run-as identity changes.
Public repositories need no credential. Even so, a saved credential avoids rate limits on anonymous fetches.
Using shared code inside a Git-source run
The fetched repository behaves like a Git folder for the duration of the run. Relative %run paths resolve inside the repository, and notebooks can import Python modules stored next to them. Check this with a small test run before depending on it. If an import fails, confirm the module's path relative to the notebook and that the file is committed on the referenced commit.
Common failures
- Path not found. The path is relative to the repository root, not the workspace. A leading slash, a workspace path such as
/Workspace/Users/..., or a.pyextension on a notebook are frequent causes. - Authentication error on fetch. The run-as identity has no valid credential for the provider, or its token has expired or lost access to the repository.
- Reference not found. The branch or tag name has a typo, or it exists only locally and was never pushed.
- Unexpected old code. The job points at a tag or commit, and you pushed fixes to the branch. Update the reference.
- Edits made in the job UI vanish. You cannot edit the notebook from a Git-source task. Change it in a Git folder or local clone, then commit and push.
- Default parameters used silently. The key in
base_parametersdoes not match the widget name. Names are case-sensitive.
Where this leads
A job from Git source is the unit that deployment automation manages. The next chapter shows how Databricks Asset Bundles describe jobs like this one in files stored in the repository, so the job definition is versioned along with the code.
Exercise
A production job uses Git source with branch main. A teammate merges a pull request at 02:05, and the job started at 02:00 and is still running. Which code does the run use, and which code will tomorrow's 02:00 run use?
Show answer
The running job uses the commit that main pointed to when the run started, so it does not see the 02:05 merge. Tomorrow's run resolves main again and uses the merged code. To prevent code from changing between runs without a release step, pin the job to a tag or commit SHA.
Exercise
A job notebook task works when you test it with source set to Workspace, but fails with "path not found" after you switch it to Git provider. The path field still says /Workspace/Repos/me/orders-pipeline/notebooks/daily_load. What should the path be?
Show answer
notebooks/daily_load. With a Git source, the path is relative to the repository root, has no leading slash, and has no file extension for notebooks.