1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Pipelines から Databricks の API を実行する方法

Posted at

概要

Azure Pipelines の標準タスクを用いて Databricks の API を実行する3つの方法を紹介します。

  1. CmdLineタスクにより Databricks REST API を実行する方法
  2. InvokeRESTAPIタスクにより Databricks REST API を実行する方法
  3. CmdLineタスクにより Databricks CLI を実行する方法

事前準備

1. Databricks にて、Databricks Workflows のジョブを作成

import time

# sleep 前のエポック秒(UNIX時間)を取得
startSec = time.time()

# 1.5 秒 止める
time.sleep(90)

image.png

2. Azure Pipeines にて パイプラインを作成後、3つの変数を定義

# 変数値 概要
1 DATABRICKS_WORKSPACE_URL Databricks Workspace の URL
2 DATABRICKS_TOKEN Databricks のシークレット
3 DATABRICKS_JOB_ID Databricks Workflows の Job ID

image.png

1. CmdLineタスクにより Databricks REST API を実行する方法

jobs:
  - job: Databrics_REST_API_by_CmdLine
    steps:
    - task: CmdLine@2
      displayName: Execute Databricks Workflow
      inputs:
        script: |
          results=$(curl -X POST $(DATABRICKS_WORKSPACE_URL)/api/2.1/jobs/run-now \
          -H 'Content-Type: application/json' \
          -H 'Authorization: Bearer $(DATABRICKS_TOKEN)' \
          -d '{"job_id": "$(DATABRICKS_JOB_ID)"}' \
          )
          echo $results

image.png

2. InvokeRESTAPIタスクにより Databricks REST API を実行する方法

jobs:
  - job: Databrics_REST_API_by_InvokeRESTAPI
    pool: server
    steps:
    - task: InvokeRESTAPI@1
      inputs:
        connectionType: 'connectedServiceName'
        serviceConnection: 'databricks_jobs'
        method: 'POST'
        headers: |
          {
          "Content-Type": "application/json",
          "Authorization": "Bearer $(DATABRICKS_TOKEN)"
          }
        body: |
          {
            "job_id": "$(DATABRICKS_JOB_ID)"
          }
        urlSuffix: 'api/2.1/jobs/run-now'

image.png

3. CmdLineタスクにより Databricks CLI を実行する方法

jobs:
  - job: Databrics_CLI
    steps:
    - task: UsePythonVersion@0
      displayName: 'Use Python 3.8'
    - task: CmdLine@2
      inputs:
        script: |
          pip install databricks-cli -q
          databricks jobs run-now --job-id $(DATABRICKS_JOB_ID)
      env:
        DATABRICKS_HOST: $(DATABRICKS_WORKSPACE_URL)
        DATABRICKS_TOKEN: $(DATABRICKS_TOKEN)

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?