`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
Percy
Percy16mo ago
Project ID: 9f4e3a16-38d9-4e01-ac73-ad467f026405
Brody
Brody16mo ago
what version of the cli are you on?
behrouz.babaki
behrouz.babakiOP16mo ago
I use version 3.4.0
Brody
Brody16mo ago
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?
behrouz.babaki
behrouz.babakiOP16mo ago
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.
Brody
Brody16mo ago
i prefer installing it with bash <(curl -fsSL cli.new) is your project token, the token for the stage environment?
behrouz.babaki
behrouz.babakiOP16mo ago
Thanks! I just realized that tokens are environment-specific. Does it mean that I cannot deploy to multiple environments using a single RAILWAY_TOKEN?
Brody
Brody16mo ago
you can always try an account token are you deploying from gitlab?
behrouz.babaki
behrouz.babakiOP16mo ago
Yes, I'm deploying from gitlab. This is the deployment job in my .gitlab-ci.yml script:
.deploy-railway:
stage: deploy
image: node:slim
variables:
RAILWAY_TOKEN: $RAILWAY_TOKEN
cache:
key: node-cache
paths:
- node_modules/
script:
- npm i @railway/cli
- ./node_modules/@railway/cli/bin/railway up --environment $CI_ENVIRONMENT_NAME
.deploy-railway:
stage: deploy
image: node:slim
variables:
RAILWAY_TOKEN: $RAILWAY_TOKEN
cache:
key: node-cache
paths:
- node_modules/
script:
- npm i @railway/cli
- ./node_modules/@railway/cli/bin/railway up --environment $CI_ENVIRONMENT_NAME
Brody
Brody16mo ago
does gitlab allow you to set different variables for different branches?
behrouz.babaki
behrouz.babakiOP16mo ago
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.
Brody
Brody16mo ago
but please stop installing the cli to your local project https://blog.railway.app/p/gitlab-ci-cd
behrouz.babaki
behrouz.babakiOP16mo ago
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.
Brody
Brody16mo ago
awesome
Want results from more Discord servers?
Add your server