a year ago
I am currently working on a project where I need to set environment variables during deployment using the Railway CLI. I noticed that the documentation references the railway variables command, but it is not clear how to set the variables through the CLI.
Here is a snippet of my current deployment workflow where I utilize Railway CLI commands:
on:
schedule:
# Run once a day at midnight UTC
- cron: '0 0 * * *'
push:
branches:
- develop
jobs:
build-push-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Railway CLI
run: bash <(curl -fsSL cli.new)
- name: Deploy new service
run: railway up --service=${{ vars.RAILWAY_SERVICE }} --environment=${{ vars.RAILWAY_ENV }} --verbose
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_PROJECT_TOKEN }}3 Replies
a year ago
Hey, This is not something the CLI supports at this time, railway variables is used to read out the variables.
Could you explain more about your usecase?
a year ago
Thank you for the clarification. Sure, I can elaborate. I need to set the DATABASE_URL environment variable for my project since my script relies on it. As it’s not a good practice to hardcode credentials like the database URL directly into the code, I have stored it in GitHub Secrets. My goal is to automatically set the DATABASE_URL value as an environment variable during the deployment workflow so that the script can access it securely.
The challenge is that I want to avoid manually setting this variable through the Railway dashboard, as I aim for a fully automated deployment process without need of initial setup. Is there any workaround or method to achieve this through the Railway CLI or another automated approach?
a year ago
You could of course call Railway's public API and upset these variables.
https://docs.railway.app/guides/public-api
