When you run a notebook from another notebook using dbutils.notebook.run, the job name of the parent notebook (the one that is scheduled with a job/workflow) is not directly accessible in the child notebook (the one being called). This is why you are not seeing the job name in the output of your usual methods
To work around this, you can pass the job name as a parameter to the child notebook. Here’s how you can do it:
- Retrieve the job name in the parent notebook: You can use the Databricks REST API to get the job name. For example
import requests
import json
run_id = dbutils.notebook.entry_point.getDbutils().notebook().getContext().currentRunId().get()
response = requests.get(f"https://<databricks-instance>/api/2.0/jobs/runs/get?run_id={run_id}",
headers={"Authorization": f"Bearer {dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get()}"})
job_name = response.json().get("job_name")
- Pass the job name to the child notebook: When calling the child notebook, pass the job name as an argument:
dbutils.notebook.run("./ABC/XYZ/another_notebook", 1000, {"job_name": job_name})
- Access the job name in the child notebook: In the child notebook, retrieve the job name from the arguments:
job_name = dbutils.widgets.get("job_name")
print(f"Job Name: {job_name}")