it is not possible to get the workspace URL/Shard name from MT/E2 because we don't inject the user-visible URL, but the driver reachable one.
But as a workaround to get the shardname in our job, we can write a file with our shard name in a particular dbfs location and read it inside the job as shown below:
dbutils.fs.put("/FileStore/Deepak-test/ShardName.txt", "https://cse2.cloud.databricks.com/")
When you will run a job, you can read that file and get the shard name from there.
dbutils.fs.head("/FileStore/Deepak-test/ShardName.txt")
Or you can create a dictionary as well which you can use to get shardname inside a job
WORKSPACES = {
"111": "workspace1",
"222": "workspace1"
}
org_id = get_notebook_context().tags().apply("orgId")
print(f"https://{WORKSPACES[org_id]}.cloud.databricks.com")