railway-environment
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEnvironment Configuration
环境配置
Query, stage, and apply configuration changes for Railway environments.
查询、暂存并应用Railway环境的配置变更。
Shell Escaping
Shell转义
CRITICAL: When running GraphQL queries via bash, you MUST wrap in heredoc to prevent shell escaping issues:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh 'query ...' '{"var": "value"}'
SCRIPTWithout the heredoc wrapper, multi-line commands break and exclamation marks in GraphQL non-null types get escaped, causing query failures.
**重要提示:**通过bash运行GraphQL查询时,必须使用here-doc包裹以避免Shell转义问题:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh 'query ...' '{"var": "value"}'
SCRIPT如果不使用here-doc包裹,多行命令会失效,且GraphQL非空类型中的感叹号会被转义,导致查询失败。
When to Use
使用场景
- User wants to create a new environment
- User wants to duplicate an environment (e.g., "copy production to staging")
- User wants to switch to a different environment
- User asks about current build/deploy settings, variables, replicas, health checks, domains
- User asks to change service source (Docker image, branch, commit, root directory)
- User wants to connect a service to a GitHub repo
- User wants to deploy from a GitHub repo (create empty service first via railway-new skill, then use this)
- User asks to change build or start command
- User wants to add/update/delete environment variables
- User wants to change replica count or configure health checks
- User asks to delete a service, volume, or bucket
- User says "apply changes", "commit changes", "deploy changes"
- Auto-fixing build errors detected in logs
- 用户想要创建新环境
- 用户想要复制环境(例如:"将生产环境复制到预发布环境")
- 用户想要切换到其他环境
- 用户询问当前构建/部署设置、变量、副本数、健康检查、域名相关问题
- 用户要求更改服务源码(Docker镜像、分支、提交记录、根目录)
- 用户想要将服务连接到GitHub仓库
- 用户想要从GitHub仓库部署(先通过railway-new技能创建空服务,再使用本技能)
- 用户要求更改构建或启动命令
- 用户想要添加/更新/删除环境变量
- 用户想要更改副本数或配置健康检查
- 用户要求删除服务、存储卷或存储桶
- 用户提到"应用变更"、"提交变更"、"部署变更"
- 自动修复日志中检测到的构建错误
Create Environment
创建环境
Create a new environment in the linked project:
bash
railway environment new <name>Duplicate an existing environment:
bash
railway environment new staging --duplicate productionWith service-specific variables:
bash
railway environment new staging --duplicate production --service-variable api PORT=3001在关联项目中创建新环境:
bash
railway environment new <name>复制现有环境:
bash
railway environment new staging --duplicate production包含服务特定变量:
bash
railway environment new staging --duplicate production --service-variable api PORT=3001Switch Environment
切换环境
Link a different environment to the current directory:
bash
railway environment <name>Or by ID:
bash
railway environment <environment-id>将当前目录关联到其他环境:
bash
railway environment <name>或通过ID切换:
bash
railway environment <environment-id>Get Context
获取上下文
bash
railway status --jsonExtract:
- - for service lookup
project.id - - for the mutations
environment.id - - default service if user doesn't specify one
service.id
bash
railway status --json提取信息:
- - 用于服务查找
project.id - - 用于变更操作
environment.id - - 用户未指定时的默认服务
service.id
Resolve Service ID
解析服务ID
If user specifies a service by name, query project services:
graphql
query projectServices($projectId: String!) {
project(id: $projectId) {
services {
edges {
node {
id
name
}
}
}
}
}Match the service name (case-insensitive) to get the service ID.
如果用户通过名称指定服务,查询项目服务:
graphql
query projectServices($projectId: String!) {
project(id: $projectId) {
services {
edges {
node {
id
name
}
}
}
}
}通过服务名称(不区分大小写)匹配获取服务ID。
Query Configuration
查询配置
Fetch current environment configuration and staged changes.
graphql
query environmentConfig($environmentId: String!) {
environment(id: $environmentId) {
id
config(decryptVariables: false)
serviceInstances {
edges {
node {
id
serviceId
}
}
}
}
environmentStagedChanges(environmentId: $environmentId) {
id
patch(decryptVariables: false)
}
}Example:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query envConfig($envId: String!) {
environment(id: $envId) { id config(decryptVariables: false) }
environmentStagedChanges(environmentId: $envId) { id patch(decryptVariables: false) }
}' \
'{"envId": "ENV_ID"}'
SCRIPT获取当前环境配置和暂存的变更。
graphql
query environmentConfig($environmentId: String!) {
environment(id: $environmentId) {
id
config(decryptVariables: false)
serviceInstances {
edges {
node {
id
serviceId
}
}
}
}
environmentStagedChanges(environmentId: $environmentId) {
id
patch(decryptVariables: false)
}
}示例:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'query envConfig($envId: String!) {
environment(id: $envId) { id config(decryptVariables: false) }
environmentStagedChanges(environmentId: $envId) { id patch(decryptVariables: false) }
}' \
'{"envId": "ENV_ID"}'
SCRIPTResponse Structure
响应结构
The field contains current configuration:
configjson
{
"services": {
"<serviceId>": {
"source": { "repo": "...", "branch": "main" },
"build": { "buildCommand": "npm run build", "builder": "NIXPACKS" },
"deploy": {
"startCommand": "npm start",
"multiRegionConfig": { "us-west2": { "numReplicas": 1 } }
},
"variables": { "NODE_ENV": { "value": "production" } },
"networking": { "serviceDomains": {}, "customDomains": {} }
}
},
"sharedVariables": { "DATABASE_URL": { "value": "..." } }
}The field in contains pending changes. The effective configuration is the base merged with the staged .
patchenvironmentStagedChangesconfigpatchFor complete field reference, see reference/environment-config.md.
For variable syntax and service wiring patterns, see reference/variables.md.
configjson
{
"services": {
"<serviceId>": {
"source": { "repo": "...", "branch": "main" },
"build": { "buildCommand": "npm run build", "builder": "NIXPACKS" },
"deploy": {
"startCommand": "npm start",
"multiRegionConfig": { "us-west2": { "numReplicas": 1 } }
},
"variables": { "NODE_ENV": { "value": "production" } },
"networking": { "serviceDomains": {}, "customDomains": {} }
}
},
"sharedVariables": { "DATABASE_URL": { "value": "..." } }
}environmentStagedChangespatchconfigpatch完整字段参考请见reference/environment-config.md。
变量语法和服务连接模式请见reference/variables.md。
Get Rendered Variables
获取渲染后的变量
The GraphQL queries above return unrendered variables - template syntax like is preserved. This is correct for management/editing.
${{shared.DOMAIN}}To see rendered (resolved) values as they appear at runtime:
bash
undefined上述GraphQL查询返回的是未渲染的变量 - 保留了这类模板语法。这对于管理/编辑操作是正确的。
${{shared.DOMAIN}}要查看运行时的**渲染后(解析完成)**的值:
bash
undefinedCurrent linked service
当前关联的服务
railway variables --json
railway variables --json
Specific service
指定服务
railway variables --service <service-name> --json
**When to use:**
- Debugging connection issues (see actual URLs/ports)
- Verifying variable resolution is correct
- Viewing Railway-injected values (RAILWAY_*)railway variables --service <service-name> --json
**适用场景:**
- 调试连接问题(查看实际URL/端口)
- 验证变量解析是否正确
- 查看Railway注入的值(RAILWAY_*开头的变量)Stage Changes
暂存变更
Stage configuration changes via the mutation. Use to automatically merge with existing staged changes.
environmentStageChangesmerge: truegraphql
mutation stageEnvironmentChanges(
$environmentId: String!
$input: EnvironmentConfig!
$merge: Boolean
) {
environmentStageChanges(
environmentId: $environmentId
input: $input
merge: $merge
) {
id
}
}Important: Always use variables (not inline input) because service IDs are UUIDs which can't be used as unquoted GraphQL object keys.
Example:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"build": {"buildCommand": "npm run build"}}}}, "merge": true}'
SCRIPT通过变更操作暂存配置变更。使用自动与现有暂存变更合并。
environmentStageChangesmerge: truegraphql
mutation stageEnvironmentChanges(
$environmentId: String!
$input: EnvironmentConfig!
$merge: Boolean
) {
environmentStageChanges(
environmentId: $environmentId
input: $input
merge: $merge
) {
id
}
}**重要提示:**始终使用变量(而非内联输入),因为服务ID是UUID,无法作为未加引号的GraphQL对象键。
示例:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"build": {"buildCommand": "npm run build"}}}}, "merge": true}'
SCRIPTDelete Service
删除服务
Use :
isDeleted: truebash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"isDeleted": true}}}, "merge": true}'
SCRIPT使用:
isDeleted: truebash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation stageChanges($environmentId: String!, $input: EnvironmentConfig!, $merge: Boolean) {
environmentStageChanges(environmentId: $environmentId, input: $input, merge: $merge) { id }
}' \
'{"environmentId": "ENV_ID", "input": {"services": {"SERVICE_ID": {"isDeleted": true}}}, "merge": true}'
SCRIPTStage and Apply Immediately
暂存并立即应用
For single changes that should deploy right away, use to stage and apply in one call.
environmentPatchCommitgraphql
mutation environmentPatchCommit(
$environmentId: String!
$patch: EnvironmentConfig
$commitMessage: String
) {
environmentPatchCommit(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}Example:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation patchCommit($environmentId: String!, $patch: EnvironmentConfig, $commitMessage: String) {
environmentPatchCommit(environmentId: $environmentId, patch: $patch, commitMessage: $commitMessage)
}' \
'{"environmentId": "ENV_ID", "patch": {"services": {"SERVICE_ID": {"variables": {"API_KEY": {"value": "secret"}}}}}, "commitMessage": "add API_KEY"}'
SCRIPTWhen to use: Single change, no need to batch, user wants immediate deployment.
When NOT to use: Multiple related changes to batch, or user says "stage only" / "don't deploy yet".
对于需要立即部署的单一变更,使用一步完成暂存和应用。
environmentPatchCommitgraphql
mutation environmentPatchCommit(
$environmentId: String!
$patch: EnvironmentConfig
$commitMessage: String
) {
environmentPatchCommit(
environmentId: $environmentId
patch: $patch
commitMessage: $commitMessage
)
}示例:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation patchCommit($environmentId: String!, $patch: EnvironmentConfig, $commitMessage: String) {
environmentPatchCommit(environmentId: $environmentId, patch: $patch, commitMessage: $commitMessage)
}' \
'{"environmentId": "ENV_ID", "patch": {"services": {"SERVICE_ID": {"variables": {"API_KEY": {"value": "secret"}}}}}, "commitMessage": "add API_KEY"}'
SCRIPT**适用场景:**单一变更,无需批量处理,用户要求立即部署。
**不适用场景:**多个相关变更需要批量处理,或用户要求"仅暂存"/"暂不部署"。
Apply Staged Changes
应用暂存的变更
Commit staged changes and trigger deployments.
Note: There is no CLI command. Use the mutation below or direct users to the web UI.
railway apply提交暂存的变更并触发部署。
**注意:**没有 CLI命令。使用下方的变更操作或引导用户前往Web UI。
railway applyApply Mutation
应用变更操作
Mutation name:
environmentPatchCommitStagedgraphql
mutation environmentPatchCommitStaged(
$environmentId: String!
$message: String
$skipDeploys: Boolean
) {
environmentPatchCommitStaged(
environmentId: $environmentId
commitMessage: $message
skipDeploys: $skipDeploys
)
}Example:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation commitStaged($environmentId: String!, $message: String) {
environmentPatchCommitStaged(environmentId: $environmentId, commitMessage: $message)
}' \
'{"environmentId": "ENV_ID", "message": "add API_KEY variable"}'
SCRIPT变更操作名称:
environmentPatchCommitStagedgraphql
mutation environmentPatchCommitStaged(
$environmentId: String!
$message: String
$skipDeploys: Boolean
) {
environmentPatchCommitStaged(
environmentId: $environmentId
commitMessage: $message
skipDeploys: $skipDeploys
)
}示例:
bash
bash <<'SCRIPT'
${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
'mutation commitStaged($environmentId: String!, $message: String) {
environmentPatchCommitStaged(environmentId: $environmentId, commitMessage: $message)
}' \
'{"environmentId": "ENV_ID", "message": "add API_KEY variable"}'
SCRIPTParameters
参数
| Field | Type | Default | Description |
|---|---|---|---|
| String! | - | Environment ID from status |
| String | null | Short description of changes |
| Boolean | false | Skip deploys (only if user explicitly asks) |
| 字段 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| String! | - | 来自status命令的环境ID |
| String | null | 变更的简短描述 |
| Boolean | false | 跳过部署(仅当用户明确要求时使用) |
Commit Message
提交信息
Keep very short - one sentence max. Examples:
- "set build command to fix npm error"
- "add API_KEY variable"
- "increase replicas to 3"
Leave empty if no meaningful description.
保持简短 - 最多一句话。示例:
- "设置构建命令以修复npm错误"
- "添加API_KEY变量"
- "将副本数增加到3"
如果没有有意义的描述,可留空。
Default Behavior
默认行为
Always deploy unless user explicitly asks to skip. Only set if user says "apply without deploying", "commit but don't deploy", or "skip deploys".
skipDeploys: trueReturns a workflow ID (string) on success.
除非用户明确要求跳过,否则始终部署。仅当用户提到"应用但不部署"、"提交但不部署"或"跳过部署"时,才设置。
skipDeploys: true成功时返回一个工作流ID(字符串)。
Auto-Apply Behavior
自动应用行为
By default, apply changes immediately.
默认情况下,立即应用变更。
Flow
流程
Single change: Use to stage and apply in one call.
environmentPatchCommitMultiple changes or batching: Use with for each change, then to apply.
environmentStageChangesmerge: trueenvironmentPatchCommitStaged**单一变更:**使用一步完成暂存和应用。
environmentPatchCommit**多个变更或批量处理:**对每个变更使用并设置,然后使用应用。
environmentStageChangesmerge: trueenvironmentPatchCommitStagedWhen NOT to Auto-Apply
不自动应用的场景
- User explicitly says "stage only", "don't deploy yet", or similar
- User is making multiple related changes that should deploy together
When you don't auto-apply, tell the user:
Changes staged. Apply them at: https://railway.com/project/{projectId} Or ask me to apply them.
Get from →
projectIdrailway status --jsonproject.id- 用户明确要求"仅暂存"、"暂不部署"或类似表述
- 用户正在进行多个相关变更,需要一起部署
当不自动应用时,告知用户:
变更已暂存。可在此处应用:https://railway.com/project/{projectId} 或告知我以应用变更。
从的获取
railway status --jsonproject.idprojectIdError Handling
错误处理
Service Not Found
服务未找到
Service "foo" not found in project. Available services: api, web, workerService "foo" not found in project. Available services: api, web, workerNo Staged Changes
无暂存变更
No patch to applyThere are no staged changes to commit. Stage changes first.
No patch to apply没有可提交的暂存变更。请先暂存变更。
Invalid Configuration
无效配置
Common issues:
- and
buildCommandcannot be identicalstartCommand - only valid with NIXPACKS builder
buildCommand - only valid with DOCKERFILE builder
dockerfilePath
常见问题:
- 和
buildCommand不能相同startCommand - 仅在使用NIXPACKS构建器时有效
buildCommand - 仅在使用DOCKERFILE构建器时有效
dockerfilePath
No Permission
无权限
You don't have permission to modify this environment. Check your Railway role.You don't have permission to modify this environment. Check your Railway role.No Linked Project
无关联项目
No project linked. Run `railway link` to link a project.No project linked. Run `railway link` to link a project.Composability
组合使用
- Create service: Use railway-service skill
- View logs: Use railway-deployment skill
- Add domains: Use railway-domain skill
- Deploy local code: Use railway-deploy skill
- 创建服务:使用railway-service技能
- 查看日志:使用railway-deployment技能
- 添加域名:使用railway-domain技能
- 部署本地代码:使用railway-deploy技能