共用方式為


作業 CLI (舊版)

重要

此檔已淘汰,且可能未更新。

此資訊適用于舊版 Databricks CLI 0.18 版和更新版本。 Databricks 建議您改用較新的 Databricks CLI 0.205 版或更新版本。 請參閱 什麼是 Databricks CLI? 。 若要尋找 Databricks CLI 的版本,請執行 databricks -v

若要從 Databricks CLI 0.18 版或更新版本移轉至 Databricks CLI 0.205 版或更新版本,請參閱 Databricks CLI 移轉

您可以將 Databricks 作業 CLI 子命令附加至 , databricks jobs 而 Databricks 作業會藉由將 CLI 子命令附加至 databricks runs 來執行 CLI 子命令。 如需 Databricks 作業執行 CLI 子命令,請參閱 執行 CLI (舊版) 。 這些子命令會一起呼叫 作業 API 作業 API 2.0

重要

Databricks 作業 CLI 支援呼叫兩個版本的 Databricks 作業 REST API:2.1 版和 2.0 版。 2.1 版新增對具有多個工作之作業協調流程的支援;請參閱 建立和執行 Azure Databricks 作業和 從作業 API 2.0 更新至 2.1 。 Databricks 建議您呼叫 2.1 版,除非您有依賴 2.0 版且無法移轉的舊版腳本。

除非另有指定,否則本文所述的程式設計行為同樣適用于 2.1 和 2.0 版。

呼叫作業 REST API 2.1 的需求

若要設定及使用 Databricks 作業 CLI(和作業執行 CLI)來呼叫作業 REST API 2.1,請執行下列動作:

  1. 將 CLI 更新為 0.16.0 版或更新版本。

  2. 執行下列其中一個動作:

    • 執行命令 databricks jobs configure --version=2.1。 這會將 設定 jobs-api-version = 2.1 新增至 Unix、Linux 或 macOS %USERPROFILE%\.databrickscfg 或 Windows 上的檔案 ~/.databrickscfg 。 所有作業 CLI (和作業執行 CLI) 子命令預設都會呼叫作業 REST API 2.1。
    • 在 Unix、Linux 或 macOS %USERPROFILE%\.databrickscfg 或 Windows 上手動將設定 jobs-api-version = 2.1 新增至 ~/.databrickscfg 檔案。 所有作業 CLI (和作業執行 CLI) 子命令預設都會呼叫作業 REST API 2.1。
    • 附加 選項 --version=2.1 (例如 databricks jobs list --version=2.1 , ) 指示作業 CLI 只針對該呼叫呼叫呼叫作業 REST API 2.1。

    如果您未採取上述任何動作,作業 CLI(和作業執行 CLI)預設會呼叫作業 REST API 2.0。

呼叫作業 REST API 2.0 的需求

若要設定及使用 Databricks 作業 CLI(和作業執行 CLI)來呼叫作業 REST API 2.0,請執行下列其中一項:

  • 使用 0.16.0 以下的 Databricks CLI 版本,或
  • 將 CLI 更新為 X.Y.Z 版或更新版本,然後執行下列其中一項:
    • 執行命令 databricks jobs configure --version=2.0。 這會將 設定 jobs-api-version = 2.0 新增至 Unix、Linux 或 macOS %USERPROFILE%\.databrickscfg 或 Windows 上的檔案 ~/.databrickscfg 。 所有作業 CLI (和作業執行 CLI) 子命令預設都會呼叫作業 REST API 2.0。
    • 在 Unix、Linux 或 macOS %USERPROFILE%\.databrickscfg 或 Windows 上手動將設定 jobs-api-version = 2.0 新增至 ~/.databrickscfg 檔案。 所有作業 CLI (和作業執行 CLI) 子命令預設都會呼叫作業 REST API 2.0。
    • 附加 選項 --version=2.1 (例如 databricks jobs list --version=2.0 , ) 指示作業 CLI 只針對該呼叫呼叫呼叫作業 REST API 2.0。

如果您未採取上述任何動作,作業 CLI(和作業執行 CLI)預設會呼叫作業 REST API 2.0。

子命令和一般用法

databricks jobs -h
Usage: databricks jobs [OPTIONS] COMMAND [ARGS]...

  Utility to interact with jobs.

  Job runs are handled by ``databricks runs``.

Options:
  -v, --version  [VERSION]
  -h, --help     Show this message and exit.

Commands:
  create   Creates a job.
    Options:
      --json-file PATH            File containing JSON request to POST to /api/2.0/jobs/create.
      --json JSON                 JSON string to POST to /api/2.0/jobs/create.
  delete   Deletes a job.
    Options:
      --job-id JOB_ID             Can be found in the URL at https://<databricks-instance>/?o=<16-digit-number>#job/$JOB_ID. [required]
  get      Describes the metadata for a job.
    Options:
    --job-id JOB_ID               Can be found in the URL at https://<databricks-instance>/?o=<16-digit-number>#job/$JOB_ID. [required]
  list     Lists the jobs in the Databricks Job Service.
  reset    Resets (edits) the definition of a job.
    Options:
      --job-id JOB_ID             Can be found in the URL at https://<databricks-instance>/?o=<16-digit-number>#job/$JOB_ID. [required]
      --json-file PATH            File containing JSON request to POST to /api/2.0/jobs/create.
      --json JSON                 JSON string to POST to /api/2.0/jobs/create.
  run-now  Runs a job with optional per-run parameters.
    Options:
      --job-id JOB_ID             Can be found in the URL at https://<databricks-instance>/#job/$JOB_ID. [required]
      --jar-params JSON           JSON string specifying an array of parameters. i.e. '["param1", "param2"]'
      --notebook-params JSON      JSON string specifying a map of key-value pairs. i.e. '{"name": "john doe", "age": 35}'
      --python-params JSON        JSON string specifying an array of parameters. i.e. '["param1", "param2"]'
      --spark-submit-params JSON  JSON string specifying an array of parameters. i.e. '["--class", "org.apache.spark.examples.SparkPi"]'

建立作業

若要顯示使用方式檔,請執行 databricks jobs create --help

一般使用方式

databricks jobs create --json-file create-job.json

作業 CLI 2.1 使用注意事項和要求範例

請參閱 從作業 API 2.0 更新至 2.1 中的 建立 。

作業 CLI 2.0 要求承載和回應範例

create-job.json

{
  "name": "my-job",
  "existing_cluster_id": "1234-567890-reef123",
  "notebook_task": {
    "notebook_path": "/Users/someone@example.com/My Notebook"
  },
  "email_notifications": {
    "on_success": [
      "someone@example.com"
    ],
    "on_failure": [
      "someone@example.com"
    ]
  }
}
{ "job_id": 246 }

提示

若要複製作業,請執行 create 命令,並使用要複製之作業的設定來傳遞 JSON 物件。 本範例會將識別碼 246 為 的作業設定複製到新作業。 它需要 jq 公用程式。

SETTINGS_JSON=$(databricks jobs get --job-id 246 | jq .settings)

databricks jobs create --json "$SETTINGS_JSON"
{ "job_id": 247 }

刪除作業

若要顯示使用方式檔,請執行 databricks jobs delete --help

databricks job delete --job-id 246

如果成功,就不會顯示任何輸出。

提示

若要刪除具有相同設定的多個作業,請取得符合該設定的作業識別碼清單,然後針對每個相符的工作識別碼執行 delete 命令。 此範例會刪除作業名稱 Untitled 為 的所有作業。 它需要 jq 公用程式。

databricks jobs list --output json | jq '.jobs[] | select(.settings.name == "Untitled") | .job_id' | xargs -n 1 databricks jobs delete --job-id

列出作業的相關資訊

若要顯示使用方式檔,請執行 databricks jobs get --help

一般使用方式

databricks jobs get --job-id 246

作業 CLI 2.1 使用注意事項和回應範例

請參閱 從作業 API 2.0 更新至 2.1 。

作業 CLI 2.0 回應範例

{
  "job_id": 246,
  "settings": {
    "name": "my-job",
    "existing_cluster_id": "1234-567890-reef123",
    "email_notifications": {
      "on_success": [
        "someone@example.com"
      ],
      "on_failure": [
        "someone@example.com"
      ]
    },
    "timeout_seconds": 0,
    "notebook_task": {
      "notebook_path": "/Users/someone@example.com/My Notebook"
    },
    "max_concurrent_runs": 1
  },
  "created_time": 1620163107742,
  "creator_user_name": "someone@example.com"
}

列出可用作業的相關資訊

若要顯示使用方式檔,請執行 databricks jobs list --help

一般使用方式

databricks jobs list

作業 CLI 2.1 使用注意事項和回應範例

請參閱 從作業 API 2.0 更新至 2.1 中的 清單 。

作業 CLI 2.0 回應範例

{
  "jobs": [
    {
      "job_id": 246,
      "settings": {
        "name": "my-job",
        "existing_cluster_id": "1234-567890-reef123",
        "email_notifications": {
          "on_success": [
            "someone@example.com"
          ],
          "on_failure": [
            "someone@example.com"
          ]
        },
        "timeout_seconds": 0,
        "notebook_task": {
          "notebook_path": "/Users/someone@example.com/My Notebook"
        },
        "max_concurrent_runs": 1
      },
      "created_time": 1620163107742,
      "creator_user_name": "someone@example.com"
    },
    ...
  ]
}

列出所有作業 (僅限 API 2.1)

若要指示 CLI 透過對 API 進行循序呼叫來傳回所有作業,請使用 --all 選項。 若要使用 --all 選項,您必須 將 API 版本設定為 2.1

databricks jobs list --all

頁面作業清單 (僅限 API 2.1)

若要傳回編頁作業清單,請使用 --limit--offset 引數。 根據預設,作業清單會以包含作業識別碼和作業名稱的資料表傳回。 若要選擇性地傳回包含作業資訊的 JSON 檔,請使用 --output JSON 引數。

若要使用 --limit--offset 引數,您必須 將 API 版本設定為 2.1

使用 --output JSON 時,清單會依作業建立日期以遞減順序傳回。 使用 --output TABLE 時,清單會依作業建立日期以遞減順序傳回,然後依作業名稱依字母順序排序。

下列範例會逐一查看作業清單 10 個作業,並以 JSON 格式傳回結果:

databricks jobs list --output JSON --limit 10
databricks jobs list --output JSON --limit 10 --offset 10
databricks jobs list --output JSON --limit 10 --offset 20

變更作業的設定

若要顯示使用方式檔,請執行 databricks jobs reset --help

一般使用方式

databricks jobs reset --job-id 246 --json-file reset-job.json

作業 CLI 2.1 使用注意事項和要求範例

請參閱 從作業 API 2.0 更新至 2.1 中的 更新 和 重設

作業 CLI 2.0 要求範例

reset-job.json

{
  "job_id": 246,
  "existing_cluster_id": "2345-678901-batch234",
  "name": "my-changed-job",
  "notebook_task": {
    "notebook_path": "/Users/someone@example.com/My Other Notebook"
  },
  "email_notifications": {
    "on_success": [
      "someone-else@example.com"
    ],
    "on_failure": [
      "someone-else@example.com"
    ]
  }
}

如果成功,就不會顯示任何輸出。

執行作業

若要顯示使用方式檔,請執行 databricks jobs run-now --help

databricks jobs run-now --job-id 246
{
  "run_id": 122,
  "number_in_job": 1
}