Upload .txt and .sh files to databricks Workspace folder.

Shriram Sethi 5 Reputation points
2025-03-27T06:53:40.9333333+00:00

I am trying to upload .txt and .sh files in the databricks workspace folder so that while starting a cluster the init script can be referred from the workspace folder, manually I am able to create the files but from azure devops pipeline its not uploading

Azure Databricks
Azure Databricks

An Apache Spark-based analytics platform optimized for Azure.


3 answers

Sort by: Oldest
  1. Vinodh247-1375 44,281 Reputation points Volunteer Moderator
    2025-03-27T16:59:18.2633333+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    To upload .txt and .sh files to a Databricks Workspace folder via Azure DevOps pipeline, you cannot use the DBFS CLI for Workspace uploads. Instead, use the Databricks REST API or the Databricks CLI (v0.205+) with workspace commands.

    Preferred Approach: Use Databricks CLI with workspace API

    1. Install Databricks CLI (v0.205 or later) in your pipeline:

    Make sure your pipeline agent installs the latest CLI and sets up authentication. Use Databricks PAT (Personal Access Token) as DATABRICKS_TOKEN.

    • script: | pip install databricks-cli --upgrade databricks configure --token <<EOF $(DATABRICKS_HOST) $(DATABRICKS_TOKEN) EOF displayName: 'Install and Configure Databricks CLI'

    2.Upload files to Workspace path

    Example: Upload a shell script to /Workspace/Shared/init/init.sh. Make sure init.sh and myfile.txt are in your repository or available in the working directory.

    • script: | databricks workspace mkdirs /Shared/init databricks workspace import init.sh /Shared/init/init.sh --format AUTO --language SHELL databricks workspace import myfile.txt /Shared/init/myfile.txt --format AUTO --language TEXT displayName: 'Upload files to Databricks Workspace'
    • Workspace path is not the same as DBFS. Init scripts in Workspace can be referred using the path: /Workspace/Shared/init/init.sh
    • Use workspace path when cluster init script source is Workspace in UI or JSON.

    Validate: Cluster JSON Snippet (Workspace-based init script). You can use this in your cluster definition (via REST API or Terraform) to attach the init script.

    "init_scripts": [
      {
        "workspace": {
          "destination": "/Shared/init/init.sh"
        }
      }
    ]
    
    

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.

    Was this answer helpful?

    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.