<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to detect if running in a workflow job? in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/63728#M2816</link>
    <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;SPAN&gt;dbutils.notebook.getContext does indeed contain information about the job run.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2024 18:21:37 GMT</pubDate>
    <dc:creator>dollyb</dc:creator>
    <dc:date>2024-03-14T18:21:37Z</dc:date>
    <item>
      <title>How to detect if running in a workflow job?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/62515#M2799</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;what's the best way to differentiate in what environment my Spark session is running? Locally I develop with databricks-connect's DatabricksSession, but that doesn't work when running a workflow job which requires SparkSession.getOrCreate(). Right now in the job I'm passing a parameter that the app is reading. Is there another robust way to detected if the app is running on a Databricks cluster or not?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 16:54:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/62515#M2799</guid>
      <dc:creator>dollyb</dc:creator>
      <dc:date>2024-03-03T16:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if running in a workflow job?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/63728#M2816</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;SPAN&gt;dbutils.notebook.getContext does indeed contain information about the job run.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 18:21:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/63728#M2816</guid>
      <dc:creator>dollyb</dc:creator>
      <dc:date>2024-03-14T18:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect if running in a workflow job?</title>
      <link>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/113344#M4890</link>
      <description>&lt;LI-CODE lang="python"&gt;import json

def get_job_context():
    """Retrieve job-related context from the current Databricks notebook."""
    # Retrieve the notebook context
    ctx = dbutils.notebook.entry_point.getDbutils().notebook().getContext()
    # Convert the context to a JSON string
    ctx_json = ctx.toJson()
    # Parse the JSON string into a Python dictionary
    ctx_dict = json.loads(ctx_json)
    # Access the 'tags' dictionary
    tags_dict = ctx_dict.get('tags', {})
    # Filter for keys containing 'job' or 'run'
    job_context = {k: v for k, v in tags_dict.items() if 'job' in k.lower() or 'run' in k.lower()}
    return job_context


def is_running_in_databricks_workflow():
    """Detect if running inside a Databricks Workflow job."""
    job_context = get_job_context()
    return 'jobName' in job_context

# Example usage
print(f"Is running in Databricks Workflow: {is_running_in_databricks_workflow()}")&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 22 Mar 2025 03:08:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/how-to-detect-if-running-in-a-workflow-job/m-p/113344#M4890</guid>
      <dc:creator>Rob-Altmiller</dc:creator>
      <dc:date>2025-03-22T03:08:17Z</dc:date>
    </item>
  </channel>
</rss>

