I have a notebook running as a job in Azure Databricks. The results are shown in a Databricks dashboard. I want the dashboard URL to be sent to the team when the run is finished.
How do I retrieve the URL of the dashboard for the current run ?
I know the job ID, I managed to get the base of the URL with
dbutils.notebook.entry_point.getDbutils().notebook().getContext().browserHostName().toString()
and I found one can get the Run ID with
dbutils.notebook.entry_point.getDbutils().notebook().getContext().currentRunId().toString()
but the URL should contain the "Run", which is different than the "Run ID". Furthermore, the URL doesn’t display a dashboard without some UUID I don’t know how to get. Where can I get these informations ?
Here is my solution :
run_id = None
url = None
try:
run_id = json.loads(dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson())["tags"]["idInJob"]
url = f"https://XXX.azuredatabricks.net/?o=YYY#job/11/run/{run_id}/dashboard/ZZZ"
except:
pass
I figured XXX
, YYY
and ZZZ
do not change along runs, you will find them by looking at your sample dashboard.
run_id
and url
will stay None
if the notebook is launched in interactive mode.