Set serveless compute environment to a task of a job

jeremy98
Honored Contributor

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?

jeremy98
Honored Contributor

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
Honored Contributor III

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

spark_python_task

jeremy98
Honored Contributor

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
Honored 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.