preDeployCommand parsing of && + develop → main merge triggers a redeploy on the develop-tied environment
seif57
PROOP

a month ago

Hi — two questions about a Next.js + Postgres project on Railway. Project: gco-hub, two services on the same repo (one tied to develop for staging, one tied to main for production). The

setup uses Dockerfile builds and a predeploy command for DB migrations + seeding.

Question 1 — preDeployCommand parsing of &&

My initial railway.json had:

"deploy": {

"preDeployCommand": ["npm run db:migrate && npm run db:seed"]

}

A single array element containing two npm scripts chained with &&.

bserved behavior on every staging deploy with this config:

- npm run db:migrate ran successfully — log shows Running migrations against postgres://***... followed by Migrations complete.

- The && chain did NOT continue to npm run db:seed. No seed output appeared.

- Deployment was reported as successful, container started normally.

- Manually running railway run npm run db:seed against the same environment works perfectly and produces the expected output.

Question: when preDeployCommand is an array of strings, are array elements run via direct exec (so shell operators like &&, |, > are treated as literal arguments), or via a shell? Your

schema (backboard.railway.app/railway.schema.json) shows "items":{"type":"string"},"maxItems":1 for the array form, which suggests array elements aren't intended for chaining — but isn't

documented anywhere I could find.

I've since switched to the string form:"preDeployCommand": "npm run db:migrate && npm run db:seed"

Could you confirm:

1. Is the string form shell-evaluated and the array form exec'd?

2. What's the canonical pattern for chaining multiple commands in a predeploy?

3. Is there a recommended way to verify the predeploy command's full stdout in the dashboard (the deploy log view in our case seems to truncate or omit the post-Migrations complete.

lines)?

Solved$20 Bounty

Pinned Solution

domehane
FREE

a month ago

Hello seif57,

you're using a dockerfile andd with dockerfile builds, && is shell-specific syntax and won't work unless you explicitly wrap the command in a shell doesn't matter if you use the array or string form without the shell wrapper it won't chain

the fix is:

"preDeployCommand": "/bin/sh -c "npm run db:migrate && npm run db:seed""

Hope this help you :)

4 Replies

Railway
BOT

a month ago

The preDeployCommand array form uses exec form (like Dockerfile ENTRYPOINT), so shell operators like && are not interpreted - they're passed as literal arguments to the process. The string form is shell-evaluated, so "npm run db:migrate && npm run db:seed" as a plain string is the correct way to chain commands. The schema's maxItems: 1 on the array form confirms it's designed for a single command, not chaining. Pre-deploy command output appears in the deploy logs under the "pre-deploy" phase in the dashboard.


Status changed to Awaiting User Response Railway about 1 month ago


seif57
PROOP

a month ago

I did that and reseeding didn't work


Status changed to Awaiting Railway Response Railway about 1 month ago


Status changed to Open Railway about 1 month ago


domehane
FREE

a month ago

Hello seif57,

you're using a dockerfile andd with dockerfile builds, && is shell-specific syntax and won't work unless you explicitly wrap the command in a shell doesn't matter if you use the array or string form without the shell wrapper it won't chain

the fix is:

"preDeployCommand": "/bin/sh -c "npm run db:migrate && npm run db:seed""

Hope this help you :)


domehane

Hello **seif57,** you're using a dockerfile andd with dockerfile builds, && is shell-specific syntax and won't work unless you explicitly wrap the command in a shell doesn't matter if you use the array or string form without the shell wrapper it won't chain the fix is: "preDeployCommand": "/bin/sh -c "npm run db:migrate && npm run db:seed"" Hope this help you :)

domehane
FREE

a month ago

or if you want to avoid escaping quotes, put both commands in a shell script in your repo and do:

"preDeployCommand": "/bin/sh ./scripts/predeploy.sh"


Status changed to Solved 0x5b62656e5d 24 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...