Share via


Tutorial: Create and deploy a bundle in the workspace

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.

    Tip

    If you have previously opened the Git folder in the editor in the workspace, you can use the workspace browser authoring contexts menu to quickly navigate to the Git folder. See Authoring contexts.

  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 then click Create and deploy .

    Create new asset bundle dialog

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.

New asset bundle

Add a notebook

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

  1. Click the Add 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!")
    

Define a job

Now define a job that runs the notebook.

  1. Click the deployment icon for the bundle to switch to the Deployments panel.

    Deployments panel icon

  2. In the Bundle resources section, click Add, then New job definition.

    Create job definition

  3. Type run-notebook into the Job name field of the Add job to existing bundle dialog. Click Add and deploy.

  4. A Deploy to dev confirmation dialog appears with information about the job resource that will be created in the dev target workspace. Click Deploy.

  5. Navigate back to the bundle's files by clicking the folder icon above the deployments icon. A job resource run-notebook.job.yml was created with basic YAML for the job and some additional commented-out example job task YAML.

  6. Add a notebook task to the job definition. Replace the example YAML in the run-notebook.job.yml file with the following:

    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 under 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 Job runs from the left navigation bar to see the bundle run. The name of the bundle job run is prefixed, for example [dev someone] run-notebook.

Next steps