Share via


Tutorial: Create and deploy a bundle in the workspace

Important

Databricks Asset Bundles in the workspace is in Public Preview.

To help you get started using Databricks Asset Bundles in the workspace, this tutorial walks you through creating a bundle with a job, deploying it, and running the job in the bundle - all from the workspace.

For requirements for using bundles in the workspace, see Databricks Asset Bundles in the workspace requirements.

For more information about bundles, see What are Databricks Asset Bundles?.

Create a bundle

First, create a bundle in the Databricks workspace:

  1. Navigate to the Git folder where you want to create your bundle.

  2. Click the Create button, then click Asset bundle. Alternatively, right click on the Git folder or its associated kebab in the workspace tree and click Create > Asset bundle:

    Create an asset bundle

  3. In the Create an asset bundle dialog, give the asset bundle a name, such as totally-awesome-bundle. The bundle name can only contain letters, numbers, dashes, and underscores. Select Empty project.

    Create new asset bundle dialog

  4. Click Create.

    New asset bundle

This creates an initial bundle in the Git folder, which includes a .gitignore Git configuration file and the required Databricks Asset Bundles databricks.yml file. The databricks.yml file contains the main configuration for the bundle. For details, see Databricks Asset Bundle configuration.

Define a job that runs a notebook

Next, add a job to your bundle that runs a notebook. The notebook in the following example prints “Hello World!”.

  1. Click the Create notebook bundle project tile. Alternatively, click the kebab for the bundle in the table of contents, and then click Create > Notebook.

  2. Rename the notebook to helloworld.

  3. Set the language of the notebook to Python and paste the following into the cell of the notebook:

    print("Hello World!")
    
  4. Click the deployment icon for the bundle to switch to the Deployments panel.

    Deployments panel icon

  5. Under Bundle resources, click Create, then Create new job definition.

    Create job definition

  6. Type run-notebook into the Job name field of the Create job definition dialog. Click Create. A job definition file run-notebook.job.yml is created, with basic YAML for the job, and some additional commented-out example YAML for a job.

  7. Now add a notebook task to the job definition. Copy and paste the following YAML into the run-notebook.job.yml file, replacing the basic YAML:

    resources:
      jobs:
        run_notebook:
          name: run-notebook
          queue:
            enabled: true
          tasks:
            - task_key: my-notebook-task
              notebook_task:
                notebook_path: ../helloworld.ipynb
    

    Job notebook task configuration YAML

For details about defining a job in YAML, see job. For YAML syntax for other supported job task types, see Add tasks to jobs in Databricks Asset Bundles.

Deploy the bundle

Next, deploy the bundle and run the job that contains the helloworld notebook task.

  1. In the Deployments pane for the bundle for Targets, click the dropdown to select the dev target workspace if it is not already selected. Target workspaces are defined in the targets mapping of the bundle’s databricks.yml. See Databricks Asset Bundle deployment modes.

    Choose target deployment

  2. Click the Deploy button. The bundle is validated and details of the validation appear in a dialog.

  3. Review the deployment details in this Deploy to dev confirmation dialog, then click Deploy.

    Deploy to dev dialog

    Important

    Deploying bundles and running bundle resources executes code as the current user. Make sure that you trust the code in the bundle, including YAML, which can contain configuration settings that run commands.

The status of the deployment is output to the Project output window.

Run the job

Deployed bundle resources are listed under Bundle resources. Click the play icon associated with the job resource to run it.

List deployed resources

Navigate to Workflows > Job runs to see the bundle run. The name of the bundle job run is prefixed, for example [dev someone] run-notebook.

Next steps