Interpolating environmental variable in the preDeployCommand
pawelgrzybek
HOBBYOP

a month ago

After so many conversations with Railway built-in AI agent, and Claude Code I probably tested all possible ways to interpolate a variable in the preDeployCommand. I tested all the permutations surrounded by single and double quotation marks, with $ or with {{ NAME }}. With no success.

Took me a while to realise that there is not a shell that executes this command, but this is a pure syscall. For some this may be obvious, but for others coming from other platforms this may come as a surprise, especially because your very own AI agent is not aware of it.

I think your "Add a Pre-Deploy Command" page can be improved by explaining this and giving a simple example.

For context, this is the example of what I initially had + all the permutations with quotation marks and vars intepolatoin methods.


migrate -path ./sql/migrations -database $DATABASE_URL up

...but this is what I ended up doing to make it work.


sh -c 'migrate -path ./sql/migrations -database $DATABASE_URL up'

This is my whole railway.toml for context.


"$schema" = "https://railway.com/railway.schema.json"

[deploy]

preDeployCommand = "sh -c 'migrate -path ./sql/migrations -database $DATABASE_URL up'"
Solved

3 Replies

Railway
BOT

a month ago

Thanks for the detailed write-up and the docs feedback. Wrapping with sh -c '...' is the correct approach when you need shell variable expansion in a pre-deploy command, and we've noted the suggestion to make this clearer in the pre-deploy command docs.


Status changed to Awaiting User Response Railway 26 days ago


pawelgrzybek
HOBBYOP

a month ago

Please let me know if there is any other, maybe cleaner way of doing it.


Status changed to Awaiting Railway Response Railway 26 days ago


Railway
BOT

a month ago

The sh -c '...' wrapper is the standard and recommended way to get shell variable expansion in a pre-deploy command, and there isn't a cleaner built-in alternative for this.


Status changed to Awaiting User Response Railway 26 days ago


Railway
BOT

19 days ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 19 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...