Skip to main content

working_directory

The working_directory field controls where a custom command's steps execute, regardless of where atmos was invoked. This is useful when commands need to run from a specific location.

Path Resolution​

  • Absolute paths are used as-is (e.g., /tmp, /home/user/scripts)
  • Relative command-level paths are resolved against the Atmos base_path, whether or not they start with ./. When the command-level field is unset, the command uses the invocation directory.
  • Relative step overrides are resolved against the command's resolved directory, or the invocation directory when the command-level field is unset. Steps without an override inherit the command directory
  • The !repo-root YAML function can be used to reference the git repository root

This is unlike a kind: step hook, where a plain relative value (no ./ prefix) resolves against the component's own working directory instead.

For example, with base_path: /repo, a command-level working_directory: commands, and a step-level working_directory: scripts, the step runs in /repo/commands/scripts. An absolute step override is used as-is.

Example: Run from Repository Root​

commands:
- name: build
description: Build the project from repository root
working_directory: !repo-root .
steps:
- make build
- make test

This ensures the build commands run from the repository root, even if you invoke atmos build from a subdirectory.

Example: Run in Temp Directory​

commands:
- name: download-tools
description: Download and extract tools in /tmp
working_directory: /tmp
steps:
- wget https://example.com/tools.tar.gz
- tar -xzf tools.tar.gz

Example: Run in Component Directory​

commands:
- name: component-init
description: Initialize a component
working_directory: components/terraform/vpc
steps:
- terraform init
- terraform validate

Since components/terraform/vpc is a relative path, it will be resolved against base_path.

tip

Use working_directory: !repo-root . when defining commands in .atmos.d/ at the repository root. This ensures commands work correctly when invoked from any subdirectory in your project.