Using file mounts with server-side execution

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 files.

#!/usr/bin/env python3
import os.path

def main():
  if os.path.exists(''):
    with open('', 'a') as f:
      f.write('\nHello World')

if __name__ == "__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 file.
  - repositoriesMatchingQuery:

# In each repository, run this command. Each repository's resulting diff is captured.
  - run: python /tmp/
    container: python:latest
      - path: ./
        mountpoint: /tmp/

# Describe the changeset (e.g., GitHub pull request) you want for each repository.
  title: Hello World
  body: My first batch change!
  branch: hello-world # Push the commit to this branch.
    message: Append Hello World to all 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

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.