You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows平台下无法在.kitchen.yml中使用ENV变量的问题求助

Fixing ERB ENV Variable Resolution in .kitchen.yml on Windows

I’ve run into this exact cross-platform quirk with Test Kitchen before, and the root issue boils down to Windows vs. Linux environment variable differences plus how Test Kitchen parses ERB in your .kitchen.yml on Windows.

Problem Breakdown

Let’s unpack why this works on Ubuntu but fails on Windows:

  • On Linux/Unix systems, PWD is a standard environment variable that holds the current working directory.
  • On Windows, there is no native PWD environment variable—Windows uses CD instead. When you reference ENV['PWD'] in your ERB, it returns nil on Windows, which breaks YAML parsing entirely, leading to that Kitchen::UserError about invalid YAML.
  • The cucumber/aruba issue you’re thinking of is likely related to the same core problem: cross-platform environment variable inconsistencies breaking template parsing.

Solutions

Here are three reliable fixes, ordered by robustness:

1. Use Ruby’s Cross-Platform Dir.pwd (Best Option)

Instead of relying on system-specific environment variables, use Ruby’s built-in Dir.pwd method—it automatically returns the correct current working directory regardless of OS, and handles path separators properly.

Update your synced_folders line to:

synced_folders:
  - ["<%= Dir.pwd %>", "/target/path/in/vm"]

2. Use Windows’ Native CD Environment Variable

If you prefer sticking to environment variables, replace ENV['PWD'] with ENV['CD'] (Windows' equivalent):

synced_folders:
  - ["<%= ENV['CD'] %>", "/target/path/in/vm"]

Note: This will break compatibility with Linux systems, so only use this if you’re exclusively running on Windows.

3. Manually Set PWD in Your Windows Terminal

If you need to keep the original ENV['PWD'] syntax for cross-platform compatibility, manually set the PWD variable before running Test Kitchen commands:
For Command Prompt:

set PWD=%CD%
kitchen list

For PowerShell:

$env:PWD = Get-Location
kitchen list

Verification Steps

  1. Save your modified .kitchen.yml
  2. Open a fresh terminal (to ensure environment variables are properly loaded)
  3. Run kitchen list—it should now parse the YAML correctly without throwing the Kitchen::UserError

内容的提问来源于stack exchange,提问作者mdo123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:50:52