Search code examples
azurepowershelldatabricksazure-databricks

import files to databricks workspace


I would like to import the files from DevOps repo to databricks workspace. Problem is that I have the .sh file. In the past code below was doing its job, which is part of this module azure.databricks.cicd.tools

Add-DatabricksDBFSFile -BearerToken $ADB_Token -Region $region `
-LocalRootFolder $initFolder -FilePattern "pyodbc.sh"  -TargetLocation '/init' -Verbose

Now I want to migrate to DatabricksPS module and I have the below code

 $initFolder = $PSScriptRoot + '\InitScripts'
 $localFilePath = Join-Path -Path $initFolder -ChildPath 'pyodbc.sh'

 Import-DatabricksWorkspaceItem -Path "/Workspace/Init" -Format "FILE" -LocalPath 
 $localFilePath -Overwrite $true

Which is not working. Below is the error

Invoke-RestMethod : {"error_code":"RESOURCE_ALREADY_EXISTS","message":"Path (/Workspace/Init) already exists and is a different type."}

Goal is to import the sh file into workspace path


Solution

  • You are using the target path as workspace directory, so you are facing this error of resource already exists with different type.

    Give the target location including the file and it runs successfully.

    Import-DatabricksWorkspaceItem -Path "/Workspace/Init/init.sh" -Format "FILE" -LocalPath "init.sh" -Overwrite $true
    

    Output:

    enter image description here

    and in workspace

    enter image description here