<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic CICD for databricks workflow jobs in Community Articles</title>
    <link>https://community.databricks.com/t5/community-articles/cicd-for-databricks-workflow-jobs/m-p/74015#M121</link>
    <description>&lt;P&gt;This post is to set up Databricks workflow jobs as a CI/CD.&lt;/P&gt;
&lt;P&gt;Below are the two essential components needed for a complete CI/CD setup of workflow jobs.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Databricks Asset Bundles(DABs)&lt;/LI&gt;
&lt;LI&gt;Azure&lt;SPAN&gt;DevOps&lt;/SPAN&gt; pipeline.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Databricks Asset Bundle ( From local terminal ) :&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;We need to use Databricks Asset Bundle(DABs) using databricks cli to deploy workflows.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please note that Databricks Asset Bundles(DABs) are available in the latest version of databricks-cli (v0.205.0 and above). The legacy version will not work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-circle"&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Run Command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;databricks bundle init&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;In the local terminal, select python project and provide some project name (workflow will be created with this name, ex. demo_wf) when prompted,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This will generate the folder structure of all the components needed for the workflow and create a folder with the project name, as shown below.&lt;/SPAN&gt;&lt;/P&gt;
&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 4.27.27 PM.png" style="width: 608px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8610iBE288734DB33B8C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 4.27.27 PM.png" alt="Screenshot 2024-06-14 at 4.27.27 PM.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Navigate to the project directory.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;cd demo_wf&lt;/LI-CODE&gt;&lt;SPAN&gt;We need the notebooks in .ipynb format inside the src folder. These notebook files will be the respective tasks in the workflow. We can also create DLT pipelines and libraries as individual tasks.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Inside the resources folder, we will have a YAML file (&amp;lt;project_name&amp;gt;_job.yml, i.e. demo_wf_job.yml) to define the task flow—sample task flow shown below.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;tasks:
  - task_key: task1
    job_cluster_key: job_cluster
    notebook_task:
      notebook_path: ../src/notebook_1.ipynb
  - task_key: task2
    job_cluster_key: job_cluster
    notebook_task:
      notebook_path: ../src/notebook_2.ipynb
    depends_on:
      - task_key: task1&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;After navigating to the project directory ( demo_wf ), Run the below command. Any syntax errors will be identified here.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;databricks bundle validate&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Finally, run the command&amp;nbsp;to deploy the workflow in the dev mode.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;databricks bundle deploy -t dev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Follow the above steps to deploy manually through the terminal. The same commands now need to be run from the build pipeline from Azure DevOps, and that will complete the CICD setup.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Databricks Asset Bundle using Azure DevOps pipeline:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Below are the steps to set up the Azure DevOps pipeline.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;We need an Azure virtual machine to run this as an agent for our DevOps pipeline, so create a virtual machine in Azure, Assign a Network security group, and set inbound rules to allow SSH (port 22) from your IP address so you can connect using SSH and do the setup on this virtual machine.&lt;/SPAN&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;We must install databrick-cli(latest version 0.212.4) on this virtual machine. &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Note: While creating the VM, we will be asked to download a .pem file (keep it safe as it is needed while connecting to the VM through an SSH).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;The next step is to install the databricks-cli on this VM and configure this machine as an agent for your Azure agent pool,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Connect to VM using the command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;ssh -i &amp;lt;path_to_pem&amp;gt;/&amp;lt;file_name&amp;gt;.pem &amp;lt;username&amp;gt;@&amp;lt;hostname&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;(&lt;/STRONG&gt;If the inbound rules created in step 1 will allow SSH from your IP address, then it will connect successfully)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Install the databricks-cli using the below command.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/main/install.sh | sudo sh&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;If you get any errors concerning unzip, then please install unzip using the below commands and re-run the above curl command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;sudo apt update -y
sudo apt install unzip -y&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Set up the VM to run as an agent in the Azure agent pool following the steps below.
&lt;UL&gt;
&lt;LI&gt;
&lt;H2&gt;&lt;FONT size="4"&gt;Create a Self-hosted Agent in Azure DevOps.&amp;nbsp;&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;To create a self-hosted agent, go to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Project Settings&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;(Bottom left)&amp;nbsp;&lt;/SPAN&gt;and select the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Agent pools&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;option under the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pipelines&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;section. Press the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Add pool&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button and configure the agent:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Select the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pool type&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as Self-hosted&lt;/LI&gt;
&lt;LI&gt;Add a descriptive pool&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(in this example&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;my-demo-pool&lt;/CODE&gt;)&lt;/LI&gt;
&lt;LI&gt;Check the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pipeline permissions&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;box so you do not need to grant permission manually&lt;/LI&gt;
&lt;LI&gt;Click on the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Create&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button&lt;/LI&gt;
&lt;LI&gt;For more details, refer to the link:&amp;nbsp;&lt;A title="Create or manage agent pool" href="https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/pools-queues?view=azure-devops&amp;amp;tabs=yaml%2Cbrowser" target="_blank" rel="noopener"&gt;Create or manage agent pool&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Now, navigate to the freshly created agent pool. On the top-right corner, press the &lt;/SPAN&gt;&lt;STRONG&gt;New Agent&lt;/STRONG&gt;&lt;SPAN&gt; button. You can create Windows, macOS, and Linux agents. Based on your VM, select the appropriate OS, then follow the instructions; in our case, we used an Ubuntu image so that it will be a Linux agent:&lt;/SPAN&gt;
&lt;UL&gt;
&lt;LI style="list-style-type: none;"&gt;
&lt;OL&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;Connect to the VM using the SSH.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;Extract the archive: Download the agent then extract it to a folder using the below linux commands in the VM terminal.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;mkdir myagent #Create a directory named myagent
cd myagent #Navigate to that agent.
wget https://vstsagentpackage.azureedge.net/agent/3.236.1/vsts-agent-linux-x64-3.236.1.tar.gz #Download the linux agent zip from the link given in the instructions using linux
tar zxvf ~/Downloads/vsts-agent-linux-x64-3.236.1.tar.gz #Unzip the agent file from the downloaded zip&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;&lt;SPAN&gt;Configure the agent: Run the config scripts in the VM terminal by running.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;./config.sh&lt;/LI-CODE&gt;&lt;SPAN&gt;Answer the questions as prompted.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;UL&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Server URL: Copy and paste the organization URL, which looks like the following:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://dev.azure.com/&amp;lt;my-organization-name&amp;gt;" target="_blank"&gt;https://dev.azure.com/&amp;lt;my-organization-name&amp;gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;Personal Access Token (PAT): Go to the &lt;STRONG&gt;Personal Access Tokens&lt;/STRONG&gt; option under the &lt;STRONG&gt;User Settings&lt;/STRONG&gt; icon. Ensure you generate a PAT with &lt;STRONG&gt;Read &amp;amp; manage&lt;/STRONG&gt; access to the Agent pools.&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent pool name: The newly created pool, which is the&lt;CODE&gt;my-demo-pool&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;in our case&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent Name: Give a meaningful name &lt;/SPAN&gt;&lt;SPAN&gt;or stay with the default&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Work folder: Press enter for the default&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent as Service: Press enter to use the default.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;&lt;SPAN&gt;Run the agent by executing the run script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;./run.sh&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Once done, you can see that the Agent is up and running under the &lt;STRONG&gt;Agents&lt;/STRONG&gt; panel.&amp;nbsp;The self-hosted agent is connected to Azure DevOps and listens for new jobs.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;For more details, refer to the link:&amp;nbsp;&lt;A title="Self-hosted agent" href="https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/linux-agent?view=azure-devops" target="_blank" rel="noopener"&gt;Self-hosted agent&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;The next step is to create azure-pipelines.yml(DevOps pipeline). Yaml should look like the one below.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool: my-demo-pool
steps:
- script: echo "Hello, world!"
  displayName: 'Run a one-line script'
- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      # Write your commands here
      echo 'Hello world'

      touch ~/.databrickscfg
      echo "[DEFAULT]" &amp;gt; ~/.databrickscfg
      echo "host = &amp;lt;workspace_host_url&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_workspace_resource_id = &amp;lt;Azure_sp_resource_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_tenant_id = &amp;lt;tenant_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_client_id = &amp;lt;spn_client_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_client_secret =&amp;lt;client_secret&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      cat ~/.databrickscfg

      databricks bundle validate
      databricks bundle deploy -t dev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After all these setups are done, To ensure our CI/CD is working as expected, the VM Agent should be up and running under the Agents panel (Project settings &amp;gt; Agent pools &amp;gt; Agents tab), and the folder structure in the main branch of Azure DevOps should look like below.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 3.59.46 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8607iCCF88FD376567A8D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 3.59.46 PM.png" alt="Screenshot 2024-06-14 at 3.59.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any changes to the Azure DevOps main branch should be deployed/reflected in the Workflow jobs of your databricks workspace.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 4.19.59 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8609i0494EDDD1D9A438C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 4.19.59 PM.png" alt="Screenshot 2024-06-14 at 4.19.59 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2024 12:17:05 GMT</pubDate>
    <dc:creator>SashankKotta</dc:creator>
    <dc:date>2024-06-14T12:17:05Z</dc:date>
    <item>
      <title>CICD for databricks workflow jobs</title>
      <link>https://community.databricks.com/t5/community-articles/cicd-for-databricks-workflow-jobs/m-p/74015#M121</link>
      <description>&lt;P&gt;This post is to set up Databricks workflow jobs as a CI/CD.&lt;/P&gt;
&lt;P&gt;Below are the two essential components needed for a complete CI/CD setup of workflow jobs.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Databricks Asset Bundles(DABs)&lt;/LI&gt;
&lt;LI&gt;Azure&lt;SPAN&gt;DevOps&lt;/SPAN&gt; pipeline.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Databricks Asset Bundle ( From local terminal ) :&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;We need to use Databricks Asset Bundle(DABs) using databricks cli to deploy workflows.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please note that Databricks Asset Bundles(DABs) are available in the latest version of databricks-cli (v0.205.0 and above). The legacy version will not work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL class="lia-list-style-type-circle"&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Run Command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;databricks bundle init&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;In the local terminal, select python project and provide some project name (workflow will be created with this name, ex. demo_wf) when prompted,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This will generate the folder structure of all the components needed for the workflow and create a folder with the project name, as shown below.&lt;/SPAN&gt;&lt;/P&gt;
&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 4.27.27 PM.png" style="width: 608px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8610iBE288734DB33B8C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 4.27.27 PM.png" alt="Screenshot 2024-06-14 at 4.27.27 PM.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Navigate to the project directory.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;cd demo_wf&lt;/LI-CODE&gt;&lt;SPAN&gt;We need the notebooks in .ipynb format inside the src folder. These notebook files will be the respective tasks in the workflow. We can also create DLT pipelines and libraries as individual tasks.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Inside the resources folder, we will have a YAML file (&amp;lt;project_name&amp;gt;_job.yml, i.e. demo_wf_job.yml) to define the task flow—sample task flow shown below.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;tasks:
  - task_key: task1
    job_cluster_key: job_cluster
    notebook_task:
      notebook_path: ../src/notebook_1.ipynb
  - task_key: task2
    job_cluster_key: job_cluster
    notebook_task:
      notebook_path: ../src/notebook_2.ipynb
    depends_on:
      - task_key: task1&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;After navigating to the project directory ( demo_wf ), Run the below command. Any syntax errors will be identified here.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;databricks bundle validate&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Finally, run the command&amp;nbsp;to deploy the workflow in the dev mode.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;databricks bundle deploy -t dev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Follow the above steps to deploy manually through the terminal. The same commands now need to be run from the build pipeline from Azure DevOps, and that will complete the CICD setup.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Databricks Asset Bundle using Azure DevOps pipeline:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Below are the steps to set up the Azure DevOps pipeline.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;We need an Azure virtual machine to run this as an agent for our DevOps pipeline, so create a virtual machine in Azure, Assign a Network security group, and set inbound rules to allow SSH (port 22) from your IP address so you can connect using SSH and do the setup on this virtual machine.&lt;/SPAN&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;We must install databrick-cli(latest version 0.212.4) on this virtual machine. &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Note: While creating the VM, we will be asked to download a .pem file (keep it safe as it is needed while connecting to the VM through an SSH).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;The next step is to install the databricks-cli on this VM and configure this machine as an agent for your Azure agent pool,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Connect to VM using the command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;ssh -i &amp;lt;path_to_pem&amp;gt;/&amp;lt;file_name&amp;gt;.pem &amp;lt;username&amp;gt;@&amp;lt;hostname&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;(&lt;/STRONG&gt;If the inbound rules created in step 1 will allow SSH from your IP address, then it will connect successfully)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;Install the databricks-cli using the below command.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/main/install.sh | sudo sh&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;SPAN&gt;If you get any errors concerning unzip, then please install unzip using the below commands and re-run the above curl command:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;sudo apt update -y
sudo apt install unzip -y&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Set up the VM to run as an agent in the Azure agent pool following the steps below.
&lt;UL&gt;
&lt;LI&gt;
&lt;H2&gt;&lt;FONT size="4"&gt;Create a Self-hosted Agent in Azure DevOps.&amp;nbsp;&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;To create a self-hosted agent, go to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Project Settings&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;(Bottom left)&amp;nbsp;&lt;/SPAN&gt;and select the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Agent pools&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;option under the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pipelines&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;section. Press the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Add pool&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button and configure the agent:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Select the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pool type&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as Self-hosted&lt;/LI&gt;
&lt;LI&gt;Add a descriptive pool&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(in this example&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;my-demo-pool&lt;/CODE&gt;)&lt;/LI&gt;
&lt;LI&gt;Check the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Pipeline permissions&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;box so you do not need to grant permission manually&lt;/LI&gt;
&lt;LI&gt;Click on the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Create&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button&lt;/LI&gt;
&lt;LI&gt;For more details, refer to the link:&amp;nbsp;&lt;A title="Create or manage agent pool" href="https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/pools-queues?view=azure-devops&amp;amp;tabs=yaml%2Cbrowser" target="_blank" rel="noopener"&gt;Create or manage agent pool&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Now, navigate to the freshly created agent pool. On the top-right corner, press the &lt;/SPAN&gt;&lt;STRONG&gt;New Agent&lt;/STRONG&gt;&lt;SPAN&gt; button. You can create Windows, macOS, and Linux agents. Based on your VM, select the appropriate OS, then follow the instructions; in our case, we used an Ubuntu image so that it will be a Linux agent:&lt;/SPAN&gt;
&lt;UL&gt;
&lt;LI style="list-style-type: none;"&gt;
&lt;OL&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;Connect to the VM using the SSH.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;Extract the archive: Download the agent then extract it to a folder using the below linux commands in the VM terminal.&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;mkdir myagent #Create a directory named myagent
cd myagent #Navigate to that agent.
wget https://vstsagentpackage.azureedge.net/agent/3.236.1/vsts-agent-linux-x64-3.236.1.tar.gz #Download the linux agent zip from the link given in the instructions using linux
tar zxvf ~/Downloads/vsts-agent-linux-x64-3.236.1.tar.gz #Unzip the agent file from the downloaded zip&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;SPAN&gt;&lt;SPAN&gt;Configure the agent: Run the config scripts in the VM terminal by running.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;./config.sh&lt;/LI-CODE&gt;&lt;SPAN&gt;Answer the questions as prompted.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;UL&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Server URL: Copy and paste the organization URL, which looks like the following:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://dev.azure.com/&amp;lt;my-organization-name&amp;gt;" target="_blank"&gt;https://dev.azure.com/&amp;lt;my-organization-name&amp;gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;Personal Access Token (PAT): Go to the &lt;STRONG&gt;Personal Access Tokens&lt;/STRONG&gt; option under the &lt;STRONG&gt;User Settings&lt;/STRONG&gt; icon. Ensure you generate a PAT with &lt;STRONG&gt;Read &amp;amp; manage&lt;/STRONG&gt; access to the Agent pools.&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent pool name: The newly created pool, which is the&lt;CODE&gt;my-demo-pool&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;in our case&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent Name: Give a meaningful name &lt;/SPAN&gt;&lt;SPAN&gt;or stay with the default&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Work folder: Press enter for the default&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Agent as Service: Press enter to use the default.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;&lt;SPAN&gt;Run the agent by executing the run script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;./run.sh&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;Once done, you can see that the Agent is up and running under the &lt;STRONG&gt;Agents&lt;/STRONG&gt; panel.&amp;nbsp;The self-hosted agent is connected to Azure DevOps and listens for new jobs.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;For more details, refer to the link:&amp;nbsp;&lt;A title="Self-hosted agent" href="https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/linux-agent?view=azure-devops" target="_blank" rel="noopener"&gt;Self-hosted agent&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="2"&gt;&lt;SPAN&gt;The next step is to create azure-pipelines.yml(DevOps pipeline). Yaml should look like the one below.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool: my-demo-pool
steps:
- script: echo "Hello, world!"
  displayName: 'Run a one-line script'
- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      # Write your commands here
      echo 'Hello world'

      touch ~/.databrickscfg
      echo "[DEFAULT]" &amp;gt; ~/.databrickscfg
      echo "host = &amp;lt;workspace_host_url&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_workspace_resource_id = &amp;lt;Azure_sp_resource_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_tenant_id = &amp;lt;tenant_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_client_id = &amp;lt;spn_client_id&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      echo "azure_client_secret =&amp;lt;client_secret&amp;gt;" &amp;gt;&amp;gt; ~/.databrickscfg
      cat ~/.databrickscfg

      databricks bundle validate
      databricks bundle deploy -t dev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After all these setups are done, To ensure our CI/CD is working as expected, the VM Agent should be up and running under the Agents panel (Project settings &amp;gt; Agent pools &amp;gt; Agents tab), and the folder structure in the main branch of Azure DevOps should look like below.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 3.59.46 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8607iCCF88FD376567A8D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 3.59.46 PM.png" alt="Screenshot 2024-06-14 at 3.59.46 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any changes to the Azure DevOps main branch should be deployed/reflected in the Workflow jobs of your databricks workspace.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-06-14 at 4.19.59 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/8609i0494EDDD1D9A438C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-06-14 at 4.19.59 PM.png" alt="Screenshot 2024-06-14 at 4.19.59 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 12:17:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/cicd-for-databricks-workflow-jobs/m-p/74015#M121</guid>
      <dc:creator>SashankKotta</dc:creator>
      <dc:date>2024-06-14T12:17:05Z</dc:date>
    </item>
  </channel>
</rss>

