How do we access databricks job parameters inside the attached notebook?

Viewed 1484

In Databrick if i have a job job request json as:

{
  "job_id": 1,
  "notebook_params": {
    "name": "john doe",
    "age": "35"
  }
}

How do i access the notebook_params inside the job attached notebook?

1 Answers

In notebooks, you can accecss parameters via Widgets using the dbutils.widgets.get function. For your example, it will be:

name = dbutils.widgets.get("name")
age = dbutils.widgets.get("age")

Please note that by default the value is string, so if you need to have age as number, you need to convert it.

Also, if you want to debug output before you put it as a job, then you need to declare corresponding widgets using one of the dbutils.widgets functions, otherwise you'll get error that widget isn't defined when doing dbutils.widgets.get. For exampple, you can use dbutils.widgets.text that allows to enter any text):

dbutils.widgets.text("name", "<default_name>", "Enter name")
dbutils.widgets.text("name", "<default_age>", "Enter age")
Related