a month ago
I am using gitlab cicd for deployment with my docker runner that has railway cli image run inside my container
stages:
- deploy
variables:
RAILWAY_TOKEN: $STAGING_RAILWAY_TOKEN
RAILWAY_PROJECT_ID: $STAGING_RAILWAY_PROJECT_ID
BACKEND_SERVICE_ID: $STAGING_BACKEND_SERVICE_ID
FRONTEND_SERVICE_ID: $STAGING_FRONTEND_SERVICE_ID
WORKER_SERVICE_ID: $STAGING_WORKER_SERVICE_ID
# Deploy Backend (omni-trail)
deploy-backend:
stage: deploy
image: ghcr.io/railwayapp/cli:latest
only:
- staging
needs:
- deploy-worker
script:
- cd backend
- echo $BACKEND_SERVICE_ID
- railway up --service=$BACKEND_SERVICE_ID --detach
environment:
name: staging-backend
deploy-frontend:
stage: deploy
image: ghcr.io/railwayapp/cli:latest
only:
- staging
script:
- cd frontend
- echo $FRONTEND_SERVICE_ID
- railway up --service=$FRONTEND_SERVICE_ID --detach
environment:
name: staging-frontend
deploy-worker:
stage: deploy
image: ghcr.io/railwayapp/cli:latest
only:
- staging
script:
- cd "backend"
- echo $WORKER_SERVICE_ID
- railway up --service=$WORKER_SERVICE_ID --detach
environment:
name: staging-worker
error
railway link --project=$STAGING_RAILWAY_PROJECT_ID --environment=$RAILWAY_ENVIRONMENT_ID
Unauthorized. Please login with railway login
The RAILWAY_TOKEN environment variable is set but may be invalid or expired.
Cleaning up project directory and file based variables00:00
ERROR: Job failed: exit status 1
1 Replies
3 days ago
"I recently encountered the exact same issue with GitLab CI/CD. Even though the RAILWAY_TOKEN was set correctly, the CLI kept throwing 'Unauthorized'.
It seems the Railway CLI (especially when using an Account Token) prefers the environment variable name RAILWAY_API_TOKEN. it work
