`railway up` always deploys to `production` environment
Project ID: 9f4e3a16-38d9-4e01-ac73-ad467f026405
I use railway CLI to deploy a web app on railway. I used a Dockerfile for deployment.
The deployment to production has been always successful. Recently, I forked a
stage
environment from the production
environment. However, it seems that I cannot switch to this environment, and the build is always deployed to production
.
Here are the steps to replicate this scenario:
1. export the RAILWAY_TOKEN
environment variable
2. install railway cli: npm i @railway/cli
3. deploy to stage
: ./node_modules/@railway/cli/bin/railway up --environment stage
I have also tried to switch to stage
using railway environment
. After choosing stage
in the menu, I recieve this message: Activated environment stage
. However, when I run railway status
right after that, I receive ... Environment: production ...
14 Replies
Project ID:
9f4e3a16-38d9-4e01-ac73-ad467f026405
what version of the cli are you on?
I use version 3.4.0
just a side note, you should be installing the cli globally and not into your project
the
RAILWAY_TOKEN
is this token a project token?Yes. The
RAILWAY_TOKEN
is a project token.
I get the same result with a global install. Regardless of that, I think I still have to install it locally if I want to use railway up
in a GitLab CI script, unless there is a preferred alternative.i prefer installing it with
bash <(curl -fsSL cli.new)
is your project token, the token for the stage environment?Thanks! I just realized that tokens are environment-specific.
Does it mean that I cannot deploy to multiple environments using a single
RAILWAY_TOKEN
?you can always try an account token
are you deploying from gitlab?
Yes, I'm deploying from gitlab.
This is the deployment job in my
.gitlab-ci.yml
script:
does gitlab allow you to set different variables for different branches?
I can create different CI jobs (
deploy-stage
, deploy-production
, etc.) for different environments and use the environment-specific RAILWAY_TOKEN
for each job. I will try this approach and will report the result here.but please stop installing the cli to your local project
https://blog.railway.app/p/gitlab-ci-cd
Sure! Thanks a lot for the blog post!
I confirm that using different
RAILWAY_TOKEN
variables in different deployment jobs resolved the issue. I'm marking this question as solved.awesome