Sourcegraph DocsSourcegraph Docs
  • Code Intelligence

    • Cody
    • Code Search
  • Code Management

    • Batch Changes
    • Code Navigation
    • Code Monitoring
    • Code Ownership
    • Code Insights
    • Notebooks
  • Platform

    • Sourcegraph Admin
    • Sourcegraph Cloud
    • Integrations
    • Development
  • CLI & API

    • Sourcegraph CLI
    • Sourcegraph GraphQL API
    • Sourcegraph Stream API
  • Help & Support

    • SLAs & Premium Support
    • Tutorials
    • Sourcegraph Accounts
    • Changelog
  1. Docs
  2. batch_changes
  3. how-tos
  4. server_side_file_mounts

Using file mounts with server-side execution

This is an all-new feature. We appreciate your feedback.

NOTE: Running a batch spec server-side with file mounts is currently only supported with Sourcegraph CLI.

File mounts are a powerful way to run custom files without directly embedding the files in your batch spec.

Writing a batch spec

In the following example, you have a Python script that appends "Hello World" to all README files.

#!/usr/bin/env python3
import os.path
 
 
def main():
  if os.path.exists('README'):
    with open('README', 'a') as f:
      f.write('\nHello World')
 
 
if __name__ == "__main__":
  main()

To use the Python script in your batch change, mount the script in a step using the mounts field. The following is an example of mounting the above Python script in a step.

name: hello-world
description: Add Hello World to READMEs
 
# Find all repositories that contain a README file.
on:
  - repositoriesMatchingQuery: file:README
 
# In each repository, run this command. Each repository's resulting diff is captured.
steps:
  - run: python /tmp/hello_appender.py
    container: python:latest
    mount:
      - path: ./hello_appender.py
        mountpoint: /tmp/hello_appender.py
 
# Describe the changeset (e.g., GitHub pull request) you want for each repository.
changesetTemplate:
  title: Hello World
  body: My first batch change!
  branch: hello-world # Push the commit to this branch.
  commit:
    message: Append Hello World to all README files
  published: false # Do not publish any changes to the code hosts yet

In this example, the Python script should live besides the batch spec file, as indicated by the path:

.
├── batch-spec.yml
└── hello_appender.py

Note that a container appropriate for the mounted file has also been chosen for this step.

Running server-side

After writing the batch spec, use the Sourcegraph CLI (src) command remote to execute the batch spec server-side.

src batch remote -f batch-spec.yml

Once successful, src provides a URL to the execution of the batch change.

On this page

  1. Using file mounts with server-side execution

    1. Writing a batch spec
    1. Running server-side