cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Set serveless compute environment to a task of a job

jeremy98
Contributor III

Hi Community,

I want to set the environment of a task inside in a job using DABs, but I got this error.

jeremy98_0-1738149373540.png

I could achieve my goal, if I set manually the task inside to be environment 2, because I need to use Python 3.11.

How can I do it through DABs?

5 REPLIES 5

jeremy98
Contributor III

Hi,

Seems that this could be set for spark_python_task:

resources:
  jobs:
    New_Job_Jan_29_2025_at_11_48_AM:
      name: New Job Jan 29, 2025 at 11:48 AM
      tasks:
        - task_key: test-py-version2
          spark_python_task:
            python_file: /Workspace/Users/<private-email>/test-python-version2.py
            source: WORKSPACE
          environment_key: env_set
      queue:
        enabled: true
      environments:
        - environment_key: env_set
          spec:
            client: "2"

Why with a notebook task couldn't be set through DAB?

saurabh18cs
Valued Contributor III

for python notebooks you have to use notebook_task and for python code file you have to use 

spark_python_task

Hi, yes I know but the point is different. I mean I would to set the environment version inside each task of a job. And seems that is possible to do it only using a spark_python_task instead of using notebook_task. And yes we are using py scripts as notebooks leveraging python magic from databricks.

saurabh18cs
Valued Contributor III

To set environment variables in notebook_task, you can use the base_parameters field to pass parameters to the notebook. These parameters can then be accessed within the notebook using dbutils.widgets.

tasks:
      - task_key: task1
        notebook_task:
          notebook_path: "/Users/your_user/notebook1"
          base_parameters:
            ENV_VERSION: "dev"

Thank you.

Can you also help me search for an online site where I can find career research essay examples? I can't hire an essay writer and that is why I am looking for a site where I can read free essay examples.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group