Scheduling Databricks Notebook from Devops Pipeline

63 Views Asked by At

I am trying to schedule a Databricks notebook from Devops pipeline. I am using the below code.

- script: |
    set -x
    # Define your Databricks workspace URL and Personal Access Token (PAT)
    DATABRICKS_WORKSPACE_URL= "https://adb-136.azuredatabricks.net"
    DATABRICKS_PAT=""

    # Define the notebook path in your Databricks workspace
    NOTEBOOK_PATH="/Users/notebook.py"

    # Create a JSON payload with the correct Cron expression
    JOB_JSON_PAYLOAD=$(cat <<-JSON
    {
      "name": "DailyJob",
      "new_cluster": {
        "spark_version": "7.3.x",
        "node_type_id": "Standard_DS3_v2",
        "num_workers": 1
      },
      "schedule": {
        "quartz_cron_expression": "0 17 * * *"
      },
      "max_concurrent_runs": 1,
      "notebook_task": {
        "notebook_path": "$NOTEBOOK_PATH"
      }
    }
    JSON
    )

    # Create a new job using the Databricks REST API
    JOB_ID=$(curl -X POST -H "Authorization: Bearer $DATABRICKS_PAT" -H "Content-Type: application/json" \
      "$DATABRICKS_WORKSPACE_URL/api/2.0/jobs/create" -d "$JOB_JSON_PAYLOAD" | jq -r '.job_id')

    # Output the created job ID
    echo "Databricks Job ID: $JOB_ID"
  
  displayName: 'Schedule Daily Job for notebook.py'

The pipeline gets completed, but I do not see the job scheduled in the databricks. Is something wrong with my code. Is there any other way to achieve this.

Thank you.

0

There are 0 best solutions below